Problem Description A mail-order house sells five different products whose retai
ID: 3628996 • Letter: P
Question
Problem DescriptionA mail-order house sells five different products whose retail prices are as follows: product 1, $2.98; product 2, $4.50; product 3, $9.98; product 4, $4.49; and product 5, $6.87. Write an application that reads a series of pairs of numbers as follows:
a) Product number
b) Quantity sold for one day
If the quantity sold for the product is over 10, then 10% off is applied to the sales. If the quantity sold for the product is over 20 then 25% off is applied to the sales. You must create a function named Calculate which has 2 parameters to calculate the sales and return the sales. See the function maximum on page 251 for reference.
Your program must use a switch structure to help determine the retail price for each product. It should calculate and display the total retail value of each product sold last week. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results.
Note: Please see the example program on pages 249 to 252 for reference.
Hint: You may want to declare 5 member data to store the total sales for each product.
Additional Problem Requirement
a) Your program must produce the prompt and the output the same as given.
b) Your program should run correctly with the same inputs and outputs as given in the sample run.
c) Your program must use a switch structure to check the product number.
d) You must include the function Calculate that return a value.
e) The sales values should be displayed with currency.
#include <iostream>
#include <iomanip>
using namespace std;
double calculate(int, double);
int main()
{
int product, quantity,error;
double total = 0.0,price;
cout << "Enter pairs of item numbers and quantities."
<< " Enter -1 for the item number to end input: ";
cin >> product;
while ( product != -1 ) {
cin >> quantity;
switch ( product ) {
case 1:
total += quantity * 2.98;
break;
case 2:
total += quantity * 4.50;
break;
case 3:
total += quantity * 9.98;
break;
case 4:
total += quantity * 4.49;
break;
case 5:
total += quantity * 6.87;
break;
default:
cout << "Invalid product code: " << product
<< " Quantity: " << quantity << ' ';
break;
}
cout << "Enter pairs of item numbers and quantities. "
<< "Enter -1 for the item number to end input: ";
cin >> product;
}
cout << setiosflags( ios::fixed | ios::showpoint )
<< "The total retail value was: " << setprecision( 2 )
<< total << endl;
return 0;
}
When I run it and enter the two numbers it doesn't give me an answer and just asks the question again.
Explanation / Answer
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
double calculate(int, double);
int main()
{
int product_number=0;
int quantity_sold=0;
double product_price=0;
double total_price=0;
cout << "Enter 0 or negative number to exit" << endl;
do
{
switch(product_number)
{
case 1 :
product_price = 2.98;
break;
case 2 :
product_price = 4.50;
break;
case 3 :
product_price = 9.98;
break;
case 4 :
product_price = 4.49;
break;
case 5 :
product_price = 6.87;
break;
}
total_price = total_price + (quantity_sold * product_price);
if(quantity_sold > 10)
{
cout<<"Total price is "<< calculate(total_price, quantity_sold);
}
else cout << "Total price is " << total_price;
cout << "Enter product Number : ";
cin >> product_number;
if (product_number > 0)
{
cout << "Enter quantity sold : ";
cin >> quantity_sold;
}
}while(product_number > 0);
system("pause");
return 0;
}
double calculate(int tp, double qs)
{
double t;
if(qs > 10 && qs <= 20)
{
t = (tp -(tp * 0.10));
}
else if(qs > 20)
{
t = (tp -(tp * 0.25));
}
return t;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.