...the right way?
Code:#include <iostream>using namespace std; int main() { int sum = 0, value = 0; while (cin>> value) sum += value; cout << "Sum is:"<< sum<<endl; return 0; }
...the right way?
Code:#include <iostream>using namespace std; int main() { int sum = 0, value = 0; while (cin>> value) sum += value; cout << "Sum is:"<< sum<<endl; return 0; }
Well since Code Blocks is just an IDE, it would suggest that you must be doing something wrong.
Perhaps you might want to consider using Code Blocks auto indent feature to give you some hints since your current indent method is hiding some problems.
Code:#include <iostream> using namespace std; int main() { int sum = 0, value = 0; while(cin >> value) sum += value; cout << "Sum is:" << sum << endl; return 0; }