C++ Standard input read until the user enters a 0

Description

C++ Standard input read until the user enters a 0

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
    cout << "Terminate the series by entering two\n negative numbers in a row\n";

    int accumulator;
    for(;;)/*from   ww w  .  j a va 2 s  .c om*/
    {
        accumulator = 0;
        cout << "Start the next sequence\n";
        for(;;){
            int nValue = 0;
            cout << "Enter next number: ";
            cin  >> nValue;

            if (nValue < 0){
                break;
            }
            accumulator += nValue;
        }
        if (accumulator == 0)
        {
            break;
        }
        cout << "The total for this sequence is " << accumulator << endl << endl;
    }
    return 0;
}



PreviousNext

Related