The local tshirt shop sells shirts retail for 12 Quantity di

The local t-shirt shop sells shirts retail for 12. Quantity discounts are given as follow: 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 non-negative input.

Solution

Here is the code for you:

#include <iostream>
#include <iomanip>
#define COST_PER_SHIRT 12
using namespace std;
int main()
{
int numOfShirts;
cout<<\"How many shirts would you like? \";
cin>>numOfShirts;
if(numOfShirts < 0)
cout<<\"Invalid Input: Please enter a nonnegative integer.\"<<endl;
else if(numOfShirts <= 4)
cout<<\"The cost per shirt is $\"<<COST_PER_SHIRT<<\" and the total cost is $\"<<fixed<<setprecision(2)<<COST_PER_SHIRT * numOfShirts<<endl;
else if(numOfShirts <= 10)
cout<<\"The cost per shirt is $\"<<COST_PER_SHIRT * 0.90<<\" and the total cost is $\"<<fixed<<setprecision(2)<<COST_PER_SHIRT * numOfShirts * 0.90<<endl;
else if(numOfShirts <= 20)
cout<<\"The cost per shirt is $\"<<COST_PER_SHIRT * 0.85<<\" and the total cost is $\"<<fixed<<setprecision(2)<<COST_PER_SHIRT * numOfShirts * 0.85<<endl;
else if(numOfShirts <= 30)
cout<<\"The cost per shirt is $\"<<COST_PER_SHIRT * 0.80<<\" and the total cost is $\"<<fixed<<setprecision(2)<<COST_PER_SHIRT * numOfShirts * 0.80<<endl;
else
cout<<\"The cost per shirt is $\"<<COST_PER_SHIRT * 0.75<<\" and the total cost is $\"<<fixed<<setprecision(2)<<COST_PER_SHIRT * numOfShirts * 0.75<<endl;
}

And the output screenshot is:

 The local t-shirt shop sells shirts retail for 12. Quantity discounts are given as follow: Write a program that prompts the user for the number of shirts requi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site