0

This is my 1st time working with C++ and im trying to learn the lanuage. I am writing a program that figures out the total sales data for five products. The code for the program is:

```
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int product;
int sold;
double price = 0.00;
double total = 0.00;
cout <<"Please enter a product number.(Press ctrl+z to end)" <<endl;
cin >> product;
while ((product = cin.get()) != EOF)
{
switch (product) {
case '1':
cout<< "How many were sold?"<<endl;
cin >> sold;
price = 2.98;
total = total + (price * sold);
cout << "Enter a product number. (Press ctrl+z to end)" << endl;
break;
case '2':
cout<< "How many were sold?"<<endl;
cin >> sold;
price = 4.50;
total = total + (price * sold);
cout << "Enter a product number. (Press ctrl+z to end)" << endl;
break;
case '3':
cout<< "How many were sold?"<<endl;
cin >> sold;
price = 9.98;
total = total + (price * sold);
cout << "Enter a product number. (Press ctrl+z to end)" << endl;
break;
case '4':
cout<< "How many were sold?"<<endl;
cin >> sold;
price = 4.49;
total = total + (price * sold);
cout << "Enter a product number. (Press ctrl+z to end)" << endl;
break;
case '5':
cout<< "How many were sold?"<<endl;
cin >> sold;
price = 6.87;
total = total +(price * sold);
cout << "Enter a product number. (Press ctrl+z to end)" << endl;
break;
case '\n':
case '\t':
case ' ':
break;
default:
cout << "Not a valid product number. Please enter another number.";
break;
}
}
cout << "The total value of merchandise sold last week was: " << fixed <<setprecision (2) << total << endl;
return 0;
}
```

The program works but to get it started I have to enter a number twice. Is there something in my code causing it to do that or is just a C++ quirk. I would greatly appreicate any help that is offered.

*Edited 3 Years Ago by pyTony*: fixed formating