Help with ERROR statement please?

This is my assignment.
Write a program that computes the quarterly average sales for a salesperson in a department store. Every three months, the store calculates the quarterly average sales for each salesperson. Display the salesperson’s name and the average. Allow the user to calculate as many salespeople’s average as desired.
1.Read the name of the salesperson from the user.
2.Read the sales made by the salesperson from the user for each month during the quarter using a for loop. Display an error message if a negative sale’s amount is entered and prompt for re-entry until it is valid. (Hint: Use a do_while loop in the body of the for loop to validate data entry. See lecture notes regarding data validation).
3.Compute the average quarterly sales for that salesperson.
4.Display the name of the salesperson and the computed quarterly average.

This is my code so far but I've taken out my error statement. I cant figure out how to make the error statement work.


#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <math.h>

using namespace std;
double ms;
double ttl;
double avg;
string spn;
string rpt = "Y";

int main()
{
do {
cout << "Enter the Salesperon's name: ";
cin >> spn;
cout << fixed << setprecision(2) << endl;
cout << "Enter the sales form each month in the quarter." << endl;
for (int x = 1; x <= 3; x++)
{
cout << "Month " << x << " Sales: $ ";
do {
cin >> ms;
} while (ms < 0);
ttl = ttl + ms;
avg = ttl / 3;
}
cout << "The quarterly average sales for " << spn << " is $" << avg << endl;
cout << "Would you like to calculate the average for another salesperson? (Y or N): ";
cin >> rpt;
}
while (rpt == "y" || rpt == "Y");


return 0;

}
Last edited on
If you've removed the statement you're having problems with, how are we supposed to help you? Your program compiles fine as is.

Line 9: You should initialize your variables. As a global, ttl defaults to 0, but there is no reason for any of your variables to be global.

Line 28: Computing avg should be done after the loop. The statement is not doing any harm where it is, just pointless to compute avg inside the loop.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.


Topic archived. No new replies allowed.