My program is supposed to accept a list of positive numbers and compute the average once the sentinel, -1, is entered. The problem I'm having is that it is adding the sentinel, or subtracting -1, from the list of values.
Here's what I have:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double arg = 0, counter = 0, sum = 0;
double average;
cout<< "Enter positive numbers or -1 to quit: \n\n";
do
{
cin >> arg;
while (arg < -1)
{
cout << "Enter only 0 and positive numbers!\n";
cin >> arg;
}
sum += arg;
counter++;
}
while (arg != -1);
average = sum/counter;
cout<< sum << "/"<<counter <<endl;
cout<< fixed<< showpoint<< setprecision(2);
cout<< "The average of your "<<counter<<" numbers is "<<average<<endl;