In: Computer Science
1.C++ uses the_______________symbol to represent the AND operator.
2.The switch statement uses the value of a(n) _____________expression to determine which group of statements to branch through.
3.C++ allows the programmer to compare numeric values using ________________________
4.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.
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
Answer:
1)
&& is used as AND operator in C++.
2)
the final value of an expression is selected to decide which case is to execute in the switch statement.
3)
equal to operator which is ==
4)
code:
#include<iostream> //i/o library
using namespace std;
int main(){
int numShirts, totalCost= 0;
do
{
cout<<"How many shirts would you
like?"<<endl; //Taking input from the user
cin>>numShirts;
}
while(numShirts<0);
if(numShirts>=5 && numShirts<=10)
{
totalCost=
(numShirts*12)*1.1;
}
else if(numShirts>=11 &&
numShirts<=20)
{
totalCost=
(numShirts*12)*1.15;
}
else if(numShirts>=21 &&
numShirts<=30)
{
totalCost=
(numShirts*12)*1.2;
}
else if(numShirts>30)
{
totalCost=
(numShirts*12)*1.25;
}
else
totalCost= numShirts*12;
cout<<"The cost per shirt is $12 and total cost
of the shirts is $"<<totalCost; //Displaying output
return 0; //This is to make sure that the program
terminates
}
Output:
Please give it a thumbs up if this helped you, also provide your valuable feedback.