Write a program using a while loop that asks the user to enter their sales for each month until they enter -1 (sentinel value). After this, it should tell the user how many months, the total sales and the average sales.
If the user enters a negative value as the first input, it should not cause an error.
The program should be able to produce the output below:
Please enter your sales for month 1: 200
Please enter your sales for month 2: 100
Please enter your sales for month 3: 0
Please enter your sales for month 4: -1
For 4 moths:
Total sales: $300.00
Average sales: $150.00
Press any key to continue.......
orPlease enter your sales for month 1: -1
For 0 months:
Total sales: $0.00
Average sales: $0.00
Press any key to continue...........
So far I've come up with:
#include <iostream>
#include <iomanip>
using namespace std;
using std::fixed;
using std::setprecision;
int main()
{
double sales = 0.0;
double totalSales = 0.0;
double average = 0.0;
int i = 0;
while (sales !=-1)
{
i <= 12; i++;
cout << "Please enter your sales for month " << i << ": ";
cin >> sales;
} //end while
cout << "For " << i << ": ";
system ("PAUSE");
return 0;
}
but am confused how it should read how many months there were and where put setprecision(2) and the fixed notation.
Please help!!!