adding previous sums
I'm trying to write a code that adds the previous. I want to keep the tally going until the user inputs zero.
for example I want it to look something like this.
input 5 answer 5
input 7 answer 12
input 10 answer 22
and so on.
here is what I have so far but I realized I don't know what the proper language should be.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
int main ()
{
int x;
int j;
while ( 1 )
{
cout << "Please enter a number: ";
cin >> x;
if ( x == 0 )
{
break;
}
else
{
cin >> j = (x+j);
cout << x << "plus previous answer is " << j;
}
}
cout << "Operation ended.";
}
|
change this: cin >> j = (x+j);
to this: j = (x+j);
Topic archived. No new replies allowed.