running tally
ok quick question. this relates to combat c++.how do i do this its kinda hard to explain
10-2 = 8
next subtraction with the same variable
8-2 = 6
notice the eight
next subtraction in the program
6-2 = 4
and so on
so how do i get my variable to do this
every time the user enters damage it just refers back to the original number instead of keeping a running tally.
[401 byte] By [
tralfas] at [2007-11-11 7:44:29]

# 2 Re: running tally
Depends where you are declaring your variable??
If you declare your variable in a loop or something the value will be changed, otherwise you will be fine? eg
for(int x=0; x<10; x++)
{
int y = 8;
y = y - x;
cout<<y;
}
Each time the loop goes around y will be set to 8 again.. However if you do it like this..
int y = 8;
for(int x=0; x<10; x++)
{
y = y - x;
cout<<y;
}
y is getting set to the value of y - x and will stay that way until the loop goes around again and the value of x changes..
I hope you inderstand what Im trying to say, but basically if you use the "=" operator you will do what your trying to do..