C++ break in case of negative number
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) { int accumulator = 0; cout << "This program sums values from the user\n" << "Terminate by entering a negative number" << endl;/*from w ww .jav a2s . c o m*/ for(;;) { int nValue = 0; cout << "Enter next number: "; cin >> nValue; if (nValue < 0) { break; } accumulator += nValue; } cout << "\nThe total is " << accumulator << endl; return 0; }