write a c++ program for this please [1]. The local t-shirt shop sells shirts tha
ID: 3698512 • Letter: W
Question
write a c++ program for this please
[1]. The local t-shirt shop sells shirts that retail for $12. Quantity discounts are given as follow: Number of Shirts Discount 5-10 1090 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. Text 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? 0 The cost per shirt is $12 and the total cost is $0 Sample Run 3: How many shirts would you like? The cost per shirt is $10.80 and the total cost is $86.40 Sample Run 4: How many shirts would you like? -2 Invalid Input: Please enter a nonnegative integerExplanation / Answer
#include<iostream>
#include<iomanip>
using namespace std;
int main() {
int num;
float price, discountprice, priceofshirt=12;
cout<<"How many shirts would you like ?"<<endl;
cin>>num;
if(num>0){
if(num>30) {
discountprice=priceofshirt-((priceofshirt*25)/100);
price=discountprice*num;
cout<<"The cost per shirt is $"<<(discountprice)<<" and the total cost is $"<<(price)<<endl;
}
else if(num>20){
discountprice=priceofshirt-((priceofshirt*20)/100);
price=discountprice*num;
cout<<"The cost per shirt is $"<<(discountprice)<<" and the total cost is $"<<(price)<<endl;
}
else if(num>10) {
discountprice=priceofshirt-((priceofshirt*15)/100);
price=discountprice*num;
cout<<"The cost per shirt is $"<<(discountprice)<<" and the total cost is $"<<(price)<<endl;
}
else if(num>=5) {
discountprice=priceofshirt-((priceofshirt*10)/100);
price=discountprice*num;
cout<<"The cost per shirt is $"<<(discountprice)<<" and the total cost is $"<<(price)<<endl;
}
else
{
discountprice=12;
price=discountprice*num;
cout<<"The cost per shirt is $"<<(discountprice)<<" and the total cost is $"<<(price)<<endl;
}
}
else
{
cout<<"Invalid Inuput: please enter a nonnegitive integer"<<endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.