# Thread: new total and carrying it over.

1. ## new total and carrying it over.

what I'm looking for is this:
to have the new total of a persons money carried over into the new game. here is some code i did with out the carrying over.

Code:
```if ( gameStatus == WON ){
w = x * 2;
cout << "You have won: " << w << endl;
newtotal = w + total;
cout << "You now have " << newtotal << " dollars. ";
newtotal = total;
}```
sorry if its badly writen.. im still new.. but what i thought was that the newtotal = total; would over write the old total. and carry it to the next game.. but it doesnt. any ideas?

2. How about total = newtotal;?

Would be my guess, but hard to tell from just this code.

3. You have your LValue backwards.
You should have
Code:
`total = newtotal;`
The value on the left becomes equal to the value on the right.
Thus, you want total to be equal to newtotal, and not vice versa.

LVALUES/RVALUES
C++ has the notion of lvalues and rvalues associated with variables and constants. The rvalue is the data value of the variable, that is, what information it contains. The "r" in rvalue can be thought of as "read" value. A variable also has an associated lvalue. The "l" in lvalue can be though of as location, meaning that a variable has a location that data or information can be put into. This is contrasted with a constant. A constant has some data value, that is an rvalue. But, it cannot be written to. It does not have an lvalue.

Another view of these terms is that objects with an rvalue, namely a variable or a constant can appear on the right hand side of a statement. They have some data value that can be manipulated. Only objects with an lvalue, such as variable, can appear on the left hand side of a statement. An object must be addressable to store a value.

Here are two examples.
int x;

x = 5; // This is fine, 5 is an rvalue, x can be an lvalue.
5 = x; // This is illegal. A literal constant such as 5 is not
// addressable. It cannot be a lvalue.

4. Code:
``` if ( gameStatus == WON ){
w = x * 2;
cout << "You have won: " << w << endl;
newtotal = w + total;
cout << "You now have " << newtotal << " dollars. ";
newtotal = total;
}

cout << "New Game? (y/n)" << endl;
cin >> newGame;
} while (newGame == 'y' || newGame == 'Y');

return 0;

}

int rollDice( void )
{
int die1, die2, workSum;

die1 = 1 + rand() %6;
die2 = 1 + rand() %6;
workSum = die1 + die2;
cout << "player rolled " << die1 << " + " << die2
<< " = " << workSum << endl;

system("PAUSE");
return workSum;```
there more if ya need it... but all im reallya sking is how would i bring the new total over to the next game. since after it asks for a new game, it clears the total data back to 100.

5. Take the intialization of total out of the loop.

6. thanks sly once again

*edit* and crazy norman, i did fix that before i saw your post. but thank you any way.