uhhh.. u obviously didnt write that code. massPounds is a variable, this is where u store the user's input. cin gets input from the user, and stores it in the massPounds variable. so, u wouldnt want to use the variable until after you have taken it in from the user.
infamous
Junior Poster in Training
77 posts since Mar 2004
Reputation Points: 47
Solved Threads: 2
First we ask the user to input massPounds
The user inputs massPounds
we multiply massPounds by some constants
we print out the result of the multiplication
We can't print out the product when someone multiplies a constant by a value input by the user BEFORE the value is input by the user. infamous is referring to the fact that someone who was confused by this point of logic couldn't have written the code with the ability demonstrated in your program. :-/
cscgal
The Queen of DaniWeb
19,421 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 229
Because C++ statements are executed *in order*. When you start the program, where you have double massGram= that is where you are saying what the value for massGram is. But you are multiplying something by massPounds which doesn't have a value yet at this point. Then, after the value for massGram is calculated, the user enters a value for massPounds. But that doesn't change the value for massGram because massGram has already been calculated.
The following is a demonstration:
int x = 5; // set value of x to 5
int y = x + 3; // set value of y to 5+3 = 8
x = 2; // change value of x to 2
y = x + 3; // set value of y to 2+3 = 5
cin >> y; // get keyboard input and set it to y's value
x = y; // set x value to current value of y
y = x + 5; // set y to current value of x+5 = user's input value + 5
cscgal
The Queen of DaniWeb
19,421 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 229
I would like to apologize if anything said was inappropriate or taken the wrong way, ElectroBoy. We are all just here to help. Please let me know if my explanation cleared up any of your confusion.
cscgal
The Queen of DaniWeb
19,421 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 229