Assume that an int variable age has been declared and already given a value and assume that a char variable choice has been declared as well. Assume further that the user has just been presented with the following menu:

S: hangar steak, red potatoes, asparagus

T: whole trout, long rice, brussel sprouts

B: cheddar cheeseburger, steak fries, cole slaw

(Yes, this menu really IS a menu!)

Write some code that reads a single character (S or T or B) into choice . Then the code prints out a recommended accompanying drink as follows:

If the value of age is 21 or lower, the recommendation is "vegetable juice" for steak, "cranberry juice" for trout, and "soda" for the burger. Otherwise, the recommendations are "cabernet", "chardonnay", and "IPA" for steak, trout, and burger respectively. Regardless of the value of age , your code should print "invalid menu selection" if the character read into choice was not S or T or B.

Respuesta :

Answer:

#include <iostream>

using namespace std;

int main()

{

   int age = 28;

   char menu_selection;

   cout << "Choose an item (S, T, or B) on the menu: ";

   

   cin >> menu_selection;

   

   if (menu_selection == 'S'){

       if (age <= 21){

           cout<<"Recommendation is vegetable juice";

       }

       else{

           cout<<"Recommendation is cabernet";

       }

   }

   else if (menu_selection == 'T'){

       if (age <= 21){

           cout<<"Recommendation is cranberry juice";

       }

       else{

           cout<<"Recommendation is chardonnay";

       }

   }

   else if (menu_selection == 'B'){

       if (age <= 21){

           cout<<"Recommendation is soda";

       }

       else{

           cout<<"Recommendation is IPA";

       }

   }

   else{

       cout<<"Invalid menu selection";

   }

   

   return 0;

}

Explanation:

Here is your solution in C++.

Initialize age, declare menu selection, and ask the user to make their choice.

Then check for each condition using if-else structure. Depending on the user choice and value of the age, print the recommendation.

ACCESS MORE