C++ cin read int values

Description

C++ cin read int values

#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;/*ww  w.j ava  2 s  .  com*/

    for(;;)
    {
        int nValue = 0;
        cout << "Enter next number: ";
        cin  >> nValue;

        if (nValue < 0)
        {
            break;
        }
        accumulator += nValue;
    }
    cout << "\nThe total is "
         << accumulator
         << endl;

    return 0;
}



PreviousNext

Related