nothing
11-25-2003, 08:22 AM
Read this please:
A mail order house sells five different products whose retail prices are: product 1 - $2.98, product 2 - $4.50, product 3 - $9.98, product 4 - $4.49, product 5 - $6.87. Write a program that reads a series of pairs of numbers as follows:
a) Product number
b) Quantity sold for one day
Your program should use a switch statement to help determine the retail price for each product. Your program should calculate and display the total retail value of all products sold last week.
This is what I have so far:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
bool switch_loop = true;
double price;
double total = 0;
int product_number, quantity_sold;
while( product_number != EOF ){
cout << "Enter product number(1-5, Ctrl + C to exit): ";
cin >> product_number;
while( switch_loop != false ){
switch( product_number ){
case 1:
price = 2.98;
switch_loop = false;
break;
case 2:
price = 4.50;
switch_loop = false;
break;
case 3:
price = 9.98;
switch_loop = false;
break;
case 4:
price = 4.49;
switch_loop = false;
break;
case 5:
price = 6.87;
switch_loop = false;
break;
default:
cout << "Number must be in range 1-5.\n";
break;
}
}
cout << "Enter quantity sold for one day: ";
cin >> quantity_sold;
What I plan to do is to keep reading a pair of numbers until the user wants to stop, and keep the total of products sold so far and the total of money made so far stored in two variables so when the user quits entering numbers I can multiply the quantity of products sold by the total price. Am I on the right track or I did not understand this problem at all? Thanks :p
A mail order house sells five different products whose retail prices are: product 1 - $2.98, product 2 - $4.50, product 3 - $9.98, product 4 - $4.49, product 5 - $6.87. Write a program that reads a series of pairs of numbers as follows:
a) Product number
b) Quantity sold for one day
Your program should use a switch statement to help determine the retail price for each product. Your program should calculate and display the total retail value of all products sold last week.
This is what I have so far:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
bool switch_loop = true;
double price;
double total = 0;
int product_number, quantity_sold;
while( product_number != EOF ){
cout << "Enter product number(1-5, Ctrl + C to exit): ";
cin >> product_number;
while( switch_loop != false ){
switch( product_number ){
case 1:
price = 2.98;
switch_loop = false;
break;
case 2:
price = 4.50;
switch_loop = false;
break;
case 3:
price = 9.98;
switch_loop = false;
break;
case 4:
price = 4.49;
switch_loop = false;
break;
case 5:
price = 6.87;
switch_loop = false;
break;
default:
cout << "Number must be in range 1-5.\n";
break;
}
}
cout << "Enter quantity sold for one day: ";
cin >> quantity_sold;
What I plan to do is to keep reading a pair of numbers until the user wants to stop, and keep the total of products sold so far and the total of money made so far stored in two variables so when the user quits entering numbers I can multiply the quantity of products sold by the total price. Am I on the right track or I did not understand this problem at all? Thanks :p