// NestedDemo - input a series of numbers. // Continue to accumulate the sum // of these numbers until the user // enters a 0. Repeat the process // until the sum is 0. #include #include int main(int nArg, char* pszArgs[]) { // the outer loop cout << "This program sums multiple series\n" << "of numbers. Terminate each sequence\n" << "by entering a negative number.\n" << "Terminate the series by entering two\n" << "negative numbers in a row\n"; // continue to accumulate sequences int nAccumulator; do { // start entering the next sequence // of numbers nAccumulator = 0; cout << "\nEnter next sequence\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; } // output the accumulated result... cout << "\nThe total is " << nAccumulator << "\n"; // ...and start over with a new sequence // if the accumulated sequence was not zero } while (nAccumulator != 0); cout << "Program terminating\n"; return 0; }