Hello i am writing a simple program that will take in numbers from a user and add them all up. When the user enters 0 the program will stop taking input from the user and display the result. This is what i have so far,it compiles but is not showing the result.
#include <iostream>
usingnamespace std;
int main(int argc, char** argv)
{
cout<<"enter a number to add up"<<endl;
cout<<"enter 0 when you are done"<<endl;
int x;
int result;
while( x!=0)
{
cin>>x;
result= x+x+x;
}
while(x=0){
cout<<result<<endl;
}
return 0;
#include <iostream>
using std::cout; using std::cin;
int main()
{
int sum = 0, num = 0;
cout << "Enter in some numbers:\n";
while (cin >> num)
sum += num;
cout << "Sum: " << sum << endl;
return 0;
}
Then change the code so that it works? If you understand the code you should be able to fix it yourself. It's not that hard...
edit:
Here you go:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
using std::cout; using std::cin; using std::endl;
int main()
{
int sum = 0, num = 0;
cout << "Enter in some numbers:\n";
do
{
cin >> num;
sum += num;
}while (num != 0);
cout << "Sum: " << sum << endl;
return 0;
}