Created
October 10, 2012 12:07
-
-
Save juanfal/3865201 to your computer and use it in GitHub Desktop.
enter numbers until 0. Sum them all
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 11.sumuntil0.cpp | |
// juanfc 2011-10-21 | |
// Ask for numbers until 0 is entered | |
// sum all the entered numbers | |
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
float s = 0; | |
float n; | |
cout << "Enter a number (0: ends): "; | |
cin >> n; | |
while (n != 0) { | |
s += n; | |
cout << "\tso far: " << s << endl; | |
cout << "enter another number (0: ends): "; | |
cin >> n; | |
} | |
cout << "Sum: " << s << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment