nothing
01-25-2004, 10:01 AM
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int quantity;
int product_number = 0;
double price;
double total = 0;
while(product_number != -1) {
cout << "Enter product number (-1 to end): ";
cin >> product_number;
cout << "\nEnter quantity: ";
cin >> quantity;
switch(product_number) {
case 1:
price = 2.98;
break;
case 2:
price = 4.50;
break;
case 3:
price = 9.98;
break;
case 4:
price = 4.49;
break;
case 5:
price = 6.87;
break;
default:
cout << "Please enter a valid product number.\n" << endl;
}
total += (price * quantity);
}
cout << "The total retail value of all products sold last week is: $" << total << endl;
return 0;
}
That is not working and I can't figure a way to end the loop. Thanks.
using std::cout;
using std::cin;
using std::endl;
int main()
{
int quantity;
int product_number = 0;
double price;
double total = 0;
while(product_number != -1) {
cout << "Enter product number (-1 to end): ";
cin >> product_number;
cout << "\nEnter quantity: ";
cin >> quantity;
switch(product_number) {
case 1:
price = 2.98;
break;
case 2:
price = 4.50;
break;
case 3:
price = 9.98;
break;
case 4:
price = 4.49;
break;
case 5:
price = 6.87;
break;
default:
cout << "Please enter a valid product number.\n" << endl;
}
total += (price * quantity);
}
cout << "The total retail value of all products sold last week is: $" << total << endl;
return 0;
}
That is not working and I can't figure a way to end the loop. Thanks.