# 尝试学习C ++

``````#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;

}
``````