Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A. Assume time is entered on the hour. Assume that time is already declared. Cod

ID: 3599252 • Letter: A

Question

A. Assume time is entered on the hour. Assume that time is already declared. Code a fall-through switch statement that will print the following messages:

When the value in time is 900: “Take an extra 20% off!”

When the value in time is 1000: “Take an extra 20% off!”

When the value in time is 1100: “Take an extra 20% off!”

When the value in time is 1200: “Take an extra 20% off!”

When the value in time is any other value: “Oops! You missed the morning sale!”

B. Code a for loop with the switch structure from A. and allow 3 attempts. Prompt for the user to enter an on-the-hour military time. When the time entered is in the correct range for the morning sale make sure you exit the loop (not the program) after the message is printed. Print the message “No more attempts left!” if it is the last attempt for an invalid entry.

Explanation / Answer

Question A

Answer:

switch(time) {

case 1000:

case 1100:

case 1200:

case 900: cout<<“Take an extra 20% off!”;<<endl; break;

default: cout<<"Oops! You missed the morning sale!"<<endl;

}

Question B

Answer:

for(int i=0;i<3;i++) {

switch(time) {

case 1000:

case 1100:

case 1200:

case 900: cout<<“Take an extra 20% off!”;<<endl; break;

default: cout<<"Oops! You missed the morning sale!"<<endl; break;

}

}

cout<<"No more attempts left!"<<endl;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote