RE: C++ program 07-26-2014, 12:18 AM
#14
I know it's a bit late reply, but incase someone else stumbles upon this thread I'd like them to know there're other ways to do it as well, one way I prefer is like this:
Code:
int main(){
// We want to initiate the values for safety precautions
int input = -1, sum = 0;
// while we're recieving inputs and the input is not equal to 0
while (cin >> input && input != 0){
// same as sum = sum+input
sum += input;
}
cout << sum;
return 0;
}
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)