#include <iostream>
#include <cstdio>
#include <cstdlib>
usingnamespace std;
int sumSequensce(void)
{
int accumulator=0;
for(;;)
{
int value = 0;
cout << "Enter next number: " << endl;
cin >> value;
if(value<0)
{
break;
}
accumulator = accumulator + value;
}
return accumulator;
}
int main(int nNumberofArgs,char* pszArgs[])
{
cout << "This program sums multiple series\n"
<< "of numbers. Terminate each sequence\n"
<< "by entering a negative number.\n"
<< "Terminate the serie by entering two\n"
<< "negative numbers in a row.\n"
<< endl;
int accumulatedValue;
for(;;)
{
cout << "Enter next sequence: " << endl;
accumulatedValue = sumSequensce();
if (accumulatedValue==0)
{
break;
}
cout << "The total is " << accumulatedValue << "\n" << endl;
}
cout << "Thank you" << endl;
system ("PAUSE");
return 0;
}
but when I compile it, it looks like this
This program sums multiple series
of numbers. Terminate each sequence
by entering a negative number.
Terminate the serie by entering two
negative numbers in a row.
Enter next sequence:
Enter next number:
The input for "next sequence" is skiped, so this is my fault, or this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int sumSequensce(void)
{
int accumulator=0;
for(;;)
{
int value = 0;
cout << "Enter next number: " << endl;
cin >> value;
if(value<0)
{
break;
}
accumulator = accumulator + value;
}
return accumulator;
}