Need help with a problem using discounts to figure a final price.
Oct 11, 2013 at 3:19am UTC
The local t-shirt shop sells shirts that retail for $12. Quantity dis-
counts are given as follow:
Number of Shirts Discount
5–10 10%
11–20 15%
21–30 20%
31 or more 25%
Write a program that prompts the user for the number of shirts required
and then computes the total price. Make sure the program accepts only
nonnegative input.
Oct 11, 2013 at 3:53am UTC
This code uses a bunch of if and else ifs to set the new price of the shirt.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
const double PRICE = 12.00;
double newPrice = 0;
int amount ;
cout << "How much shirts do you want? "
cin >> amount ;
if (amount >= 5 && amount <= 10)
newPrice = PRICE - (PRICE * 0.1)
else if (amount >= 11 && amount <= 20)
newPrice = PRICE - (PRICE * 0.15)
else if (amount >= 21 && amount <= 30)
newPrice = PRICE - (PRICE * 0.2)
else if (amount >= 31)
newPrice = PRICE - (PRICE * 0.25)
else
newPrice = PRICE;
cout << "Buying " << amount << " shirt(s) gives you a price of "
<< newPrice << " per shirt." << endl;
cout << "Instead of the original " << PRICE << " per shirt."
How much shirts do you want? 15
Buying 15 shirt(s) gives you a price of 10.2 per shit.
Instead of the original 12 per shirt.
Last edited on Oct 11, 2013 at 3:58am UTC
Topic archived. No new replies allowed.