Skip to content

Instantly share code, notes, and snippets.

@juanfal
Created October 10, 2012 12:07
Show Gist options
  • Save juanfal/3865201 to your computer and use it in GitHub Desktop.
Save juanfal/3865201 to your computer and use it in GitHub Desktop.
enter numbers until 0. Sum them all
// 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