The local t-shirt shop sells shirts that retail for $12. Quantity discounts are
ID: 3580015 • Letter: T
Question
The local t-shirt shop sells shirts that retail for $12. Quantity discounts are given as follow:
Number of Shirts Discount
4 or less 0%
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.
Use the following sample runs to guide you:
Sample Run 1:
How many shirts would you like ?
4
The cost per shirt is $12 and the total cost is $48
Sample Run 2:
How many shirts would you like ? How many shirts would you like ?
0
The cost per shirt is $12 and the total cost is $0
Sample Run 3:
How many shirts would you like ? How many shirts would you like ?
8
The cost per shirt is $10.80 and the total cost is $86.40 $86.40
Sample Run 4:
How many shirts would you like ? How many shirts would you like ?
-2
Invalid Input: Please enter a nonnegative integer Invalid Input: Please enter a nonnegative integer
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int s;
float total;
cout << "How many shirts would you like ? " ;
cin >> s;
if(s >= 0){
// case 1
if(s < 5)
total = s*12;
// case 2
else if(s < 11)
total = s*12*0.9;
// case 3
else if(s<21)
total = s*12*0.85;
// case 4
else if(s<31)
total = s*12*0.8;
// case 5
else
total = s*12*0.75;
cout << "The cost per shirt is $12 and the total cost is $" << total;
}
else
cout << "Invalid Input: Please enter a nonnegative integer Invalid Input: Please enter a nonnegative integer";
return 0;
}
/*
How many shirts would you like ?
8
The cost per shirt is $12 and the total cost is $86.4
sh-4.2$ main
How many shirts would you like ?
-2
Invalid Input: Please enter a nonnegative integer Invalid Input: Please enter a non
negative integer
sh-4.2$ main
How many shirts would you like ?
0
The cost per shirt is $12 and the total cost is $0
sh-4.2$ main
How many shirts would you like ?
2
The cost per shirt is $12 and the total cost is $24
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.