Need some help to total these numbers:


#include <iostream>
using namespace std;

int main()
{// start
int x = 1, xx = 0;
while( x!=0)
{
cout<<"enter a number to add up"<<endl;
while( x!=0)
cin>>x;
xx = xx + x;
}
cout << xx;
return 0;
} //end

I am not getting a running total when adding these numbers - I thought xx = xx + x would give me the grand total, but it do not.
What do I have wrong!!!













Last edited on

1
2
3
4
5
6
7
8
9
10
11
int x=1,xx=0;
while( x!=0)
{
cout<<"enter a number to add, zero to exit"<<endl;
cin>>x;

xx = xx+x;

}

cout << xx;
Last edited on
Topic archived. No new replies allowed.