// BreakDemo - input a series of numbers. // Continue to accumulate the sum // of these numbers until the user // enters a 0. #include #include int main(int nArg, char* pszArgs[]) { // input the loop count int nAccumulator = 0; cout << "This program sums values entered " << "by the user\n"; cout << "Terminate the loop by entering " << "a negative number\n"; // loop "forever" for(;;) { // fetch another number int nValue = 0; cout << "Enter next number: "; cin >> nValue; // if it's negative... if (nValue < 0) { // ...then exit break; } // ...otherwise add the number to the // accumulator nAccumulator = nAccumulator + nValue; } // now that we've exited the loop // output the accumulated result cout << "\nThe total is " << nAccumulator << "\n"; return 0; }