In: Computer Science
PLEASE ANSWER IN C
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:
(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.
#include <stdio.h>
int main()
{
int age;
printf("Enter the age: ");
scanf("%d", &age);//taking input for the age
//following is to print the menu
printf("S: hangar steak, red potatoes, asparagus\nT: whole trout, long rice, brussel sprouts\nB: cheddar cheeseburger, steak fries, cole slaw\n");
printf("\nEnter your choice: ");//asking user for choice
while(getchar()!='\n');//clearing the input buffer
char c;
scanf("%c", &c);//taking the input of choice
printf("\n\n");
//following is to print the desired output
if(c=='S')
{
if(age<=21)
{
printf("Vegetable Juice\n");
}
else printf("Cabernet\n");
}
else if(c=='T')
{
if(age<=21)printf("cranberry juice\n");
else printf("chardonnay\n");
}
else if(c=='B')
{
if(age<=21)printf("soda\n");
else printf("IPA\n");
}
else
{
printf("invalid menu selection\n");
}
}
//Code Ends Here