change this nested -ifstructure to a switch statements. use breaks ONLY when nee
ID: 3553342 • Letter: C
Question
change this nested -ifstructure to a switch statements. use breaks ONLY when needed.
if(choice=='A' || choice == 'a')
{
rate=.15;
}
else
{
if(choice=='B' || choice == 'b')
{
rate=.10;
}
else
{
if(choice=='C' || choice == 'D')
{
rate=.05;
}
else
{
rate=.02;
}
}
}
2.
evaluate considering
bool P= false;
bool Q= true;
bool R=true;
int i= 1;
int j= 0;
a. 2*4+3>12
b. !!P
c. !j
d. j=i
e. i = j
f. P || Q&& !P || !Q
3. How many times will this code print, "Enter your discount code of either P or G".? Valid codes are P and G or
do
{
cout<<"Enter your discount code of either P or G: ";
cin>>code;
}while (code != 'P' || code != 'G');
Explanation / Answer
use header file <cctype> for converting choice to lower case
switch(tolower(choice))
{
case 'a':
rate=.15;
break;
case 'b':
rate=.10;
break;
case 'c':
rate=.05;
case 'd':
rate=.05;
break;
default:
rate=.02
break;
}
2)
a. 2*4+3>12 False
b. !!P P=False
c. !j True or j=1
d. j=i True or j=1
e. i = j True or i=1
f. P || Q&& !P || !Q True
3)
Atleast once or until the code !=P or code != G
it is do while loop
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.