Home Segments Index Top Previous Next

46: Mainline

To change the value of a variable, you use the assignment operator, =. Three assignment statements appear in the following program:

#include 
main ( ) {
  int result, height = 11, width = 9, length = 40;
  result = height;           
  result = result * width;   
  result = result * length;  
  cout << "The volume of the box car is "; 
  cout << result; 
  cout << endl; 
} 
--- Result --- 
The volume of the box car is 3960 

Of course, this program is a bit awkward—the only reason to split the computation of volume into three separate statements is to demonstrate that a variable can be assigned and then reassigned.