Question

In: Computer Science

1.C++ uses the_______________symbol to represent the AND operator. 2.The switch statement uses the value of a(n)...

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

Solutions

Expert Solution

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.


Related Solutions

WRITTEN IN C PLEASE. Write a switch statement that tests the value of the char variable...
WRITTEN IN C PLEASE. Write a switch statement that tests the value of the char variable response and performs the following actions: if response is y, the message Your request is being processed is printed if response is n, the message Thank you anyway for your consideration is printed if response is h, the message Sorry, no help is currently available is printed for any other value of response, the message Invalid entry; please try again is printed
Using c# , Write a program using a switch statement that takes one character value from...
Using c# , Write a program using a switch statement that takes one character value from the user and checks whether the entered value is an arithmetic operator (+, -, * , /) If not the program display a message that it not of the operators ( (+, -, * , /) .
Show that (a)Sn=<(1 2),(1 3),……(1 n)>. (b)Sn=<(1 2),(2 3),……(n-1 n)> (c)Sn=<(1 2),(1 2 …… n-1 n)>
Show that (a)Sn=<(1 2),(1 3),……(1 n)>. (b)Sn=<(1 2),(2 3),……(n-1 n)> (c)Sn=<(1 2),(1 2 …… n-1 n)>
Write a switch statement that uses the colour of a swab sample of COVID testing vehicle...
Write a switch statement that uses the colour of a swab sample of COVID testing vehicle to send a message to a local doctor. Use the messages given for each colour in the table below. Justify your answer.                                                                                         Colour Message Blue “No virus” Yellow “Needs to be under observation” Red “Needs to be admitted in COVID ward”
Write a switch statement that uses the colour of a swab sample of COVID testing vehicle...
Write a switch statement that uses the colour of a swab sample of COVID testing vehicle to send a message to a local doctor. Use the messages given for each colour in the table below. Justify your answer.                                                                                         Colour Message Blue “No virus” Yellow “Needs to be under observation” Red “Needs to be admitted in COVID ward”
Write a switch statement that uses the colour of a swab sample of COVID testing vehicle...
Write a switch statement that uses the colour of a swab sample of COVID testing vehicle to send a message to a local doctor. Use the messages given for each colour in the table below. Justify your answer.                                                                                         Colour Message Blue “No virus” Yellow “Needs to be under observation” Red “Needs to be admitted in COVID ward”
Discuss the purpose of a switch below:    1. Benefits of using a switch    2....
Discuss the purpose of a switch below:    1. Benefits of using a switch    2. Types of switches    3. How is a switch used in a network infrastructure
In the main(), below, write a program that uses a switch-statement to choose between three numbers....
In the main(), below, write a program that uses a switch-statement to choose between three numbers. The number, choice, should be prompted for and each choice should print out a unique statement. Also, the prompt should continue indefinitely (i.e. keep prompting until the user force-quits the program), and there should be a general catch-all if the user enters other than the three possible choices. #include <iostream> #include <iomanip> using namespace std; int main() { <your answer goes here> return 0;...
Analysis and Discussion about if, if else, else if statement and Switch C programming write on...
Analysis and Discussion about if, if else, else if statement and Switch C programming write on your computer font
A Switch/case statement allows multiway branching based on the value of an integer variable. In the...
A Switch/case statement allows multiway branching based on the value of an integer variable. In the following example, the switch variable s is specified to be assumed to be one of three values ​​of [0, 2], and a different action for each case becomes: case 0: a = a - 1; break; case 1: a = a + 2; break; case 2: b = 3 * b; break; Shows how such statements can be compiled into MiniMIPS assembly instructions.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT