Question

In: Computer Science

Assume that an int variable age has been declared and already given a value and assume...

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.

Please answer in C code

Solutions

Expert Solution

Thanks for the question.


Here is the completed code for this problem.

Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please rate the answer.

Thanks!


===========================================================================

#include<stdio.h>

int main(){
  
  
   int age=10; // you can change the age here
   char choice;
  
   printf("Enter your choice (S or T or B)? ");
   scanf("%c",&choice);
  
   // first validate the choice are either S or T or B
  
   if(choice=='S' || choice =='T' || choice =='B'){
      
      
       // once the choice are correct check the age is within 21
      
       if(age<21) {
          
           if( choice=='S') printf("You should go for Vegetable Juice.\n");
  
           else if(choice=='T') printf("You should go for Cranberry Juice.\n");
  
           else if(choice=='B') printf("You should go for Soda.\n");
          
       }
      
       // choice are either S or T or B but age is greater than 21
       else{
          
           if( choice=='S') printf("You should go for cabernet.\n");
  
           else if(choice=='T') printf("You should go for chardonnay.\n");
  
           else if(choice=='B') printf("You should go for IPA.\n");
          
       }
      
      
   }
   else{
       // when choice is neither S or T or B
      
       printf("Invalid menu selection.\n");
   }
  
  
  
}

=========================================================================


Related Solutions

1. Assume that total has already been declared as a double variable and received a value,...
1. Assume that total has already been declared as a double variable and received a value, and discountRate has been declared as a double variable, you don’t need to declare them again. You write one if statement (not multiple individual if statements) for following requirements. when total is less than 50, set discountRate to 0.0; when total is equal to or greater than 50 and less than 100, set discountRate to 0.05; when total is equal to or greater than...
This is C++ programming Given an int variable k, an int array incompletes that has been...
This is C++ programming Given an int variable k, an int array incompletes that has been declared and initialized, an int variable nIncompletes that contains the number of elements in the array, an int variable studentID that has been initialized, and an int variable numberOfIncompletes, Write code that counts the number of times the value of studentID appears in incompletes and assigns this value to numberOfIncompletes. You may use only k, incompletes, nIncompletes, studentID, and numberOfIncompletes. I tried this code...
Given an int variable k, write an expression whose value is the k-th character in the String variable word.
1. Given an int variable k, write an expression whose value is the k-th character in the String variable word. Assume thatword has been initialized and that the value ofk is non-negative and less than the length ofword.Example 1: if k's value is 3 andword is "spring", the value of the expression would be 'i'.Example 2: if k's value is 0 andword is "fall", the value of the expression would be 'f'.2. Given an int variable k, write an expression whose...
Python 1.)Assume that name is a variable of type String that has been assigned a value....
Python 1.)Assume that name is a variable of type String that has been assigned a value. Write an expression whose value is the last character of the value of name. So if the value of name were "Blair" the expression's value would be 'r'. 2.)Assume that word is a variable of type String that has been assigned a value. Write an expression whose value is a String consisting of the last three characters of the value of word. So if...
a) Given a variable word that has been assigned a string value,write a string expression...
a) Given a variable word that has been assigned a string value, write a string expression that parenthesizes the value of word. So, if word contains "sadly", the value of the expression would be the string "(sadly)"b) Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that prints the value of price in the form "X dollars and Y cents" on a line by itself. So,...
Given a String variable named sentence that has been initialized, write an expression whose value is...
Given a String variable named sentence that has been initialized, write an expression whose value is the the very last character in the String referred to by sentence. write it in python
a. Assume that x is a variable that has been given a string value. Write an expression whose value is True if and only if x is an octal (Base 8) digits (0-7)
In Python: 1 line short expressionsa. Assume that x is a variable that has been given a string value. Write an expression whose value is True if and only if x is an octal (Base 8) digits (0-7)b. Assume that x is a variable that has been given a string value. Write an expression whose value is True if and only if x is an letter.c. Assume that x is a variable that has been given a string value. Write...
Assume that a simple random sample has been selected and test the given claim. Use the​P-value...
Assume that a simple random sample has been selected and test the given claim. Use the​P-value method for testing hypotheses. Identify the null and alternative​ hypotheses, test​statistic, P-value, and state the final conclusion that addresses the original claim. "The ages of actresses when they won an acting award is summarized by the statistics n=84​, x=35.1 ​years, and s=11.4 years. Use a 0.01 significance level to test the claim that the mean age of actresses when they win an acting award...
When a variable is declared, it may also be initialized (given its initial – meaning first...
When a variable is declared, it may also be initialized (given its initial – meaning first – value) using the assignment operator (an equals sign). What is the initial value of cupSize?
Assume the random variable X has a binomial distribution with the given probability of obtaining a...
Assume the random variable X has a binomial distribution with the given probability of obtaining a success. Find the following probability, given the number of trials and the probability of obtaining a success. Round your answer to four decimal places. P(X=6), n=10 , p=0.5
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT