Question

In: Computer Science

PLEASE ANSWER IN C Assume that an int variable age has been declared and already given...

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:

  • 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.

Solutions

Expert Solution

  • #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


Related Solutions

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...
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...
Please answer with a new answer not one that has already been answered on here before....
Please answer with a new answer not one that has already been answered on here before. Many supervisors are not well-trained on the difficult task of terminating an employee and instead resort to other methods of forcing someone out of the organization. Methods include giving the employee unpleasant work tasks, reducing their hours, or modifying their jobs in some negative way. What are the ethical issues raised by this strategy and what are the risks to the organization?
PLEASE ANSWER C&D ONLY . THE REST HAS ALREADY BEEN ANSWERED. Say the marginal tax rate...
PLEASE ANSWER C&D ONLY . THE REST HAS ALREADY BEEN ANSWERED. Say the marginal tax rate is 20 percent and that government expenditures do not change with output. Say also that the economy is at potential output and that the deficit is $450 billion.     a. What is the size of the cyclical deficit? Answer = $0   b. What is the size of the structural deficit?    Answer = $450 billion.    c. How would your answers to a and...
Please answer these The following array is declared: int grades[20]; a. Write a printf() statement that...
Please answer these The following array is declared: int grades[20]; a. Write a printf() statement that can be used to display values of the first, third, and seventh elements of the array. b. Write a scanf() statement that can be used to enter values into the first, third, and seventh elements of the array. c. Write a for loop that can be used to enter values for the complete array. d. Write a for loop that can be used to...
For C++ Assume that word is a variable of type string that has been assigned a...
For C++ Assume that word is a variable of type string that has been assigned a value. Assume furthermore that this value always contains the letters "dr" followed by at least two other letters. For example: "undramatic", "dreck", "android", "no-drip". Assume that there is another variable declared, drWord, also of type string. Write the statements needed so that the 4-character substring word of the value of word starting with "dr" is assigned to drWord. So, if the value of word...
C programming, if you already answer this, please skip, thanks fill in ... /* In this...
C programming, if you already answer this, please skip, thanks fill in ... /* In this program, read stdin a line at a time, and print the longest line. If that line is longer than 30 characters, print it in the format first ten characters...middle ten characters...last ten characters. Note: The longest line can be quite long. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> #define BLOCKSIZE 100 char* readline() {    char* result = NULL;    int rsize;...
Given an int b, set the variable answer to equal "negative" if b is less than...
Given an int b, set the variable answer to equal "negative" if b is less than 0; set answer to "positive" if b is greater than 0; and set it to "zero" if b equals zero in python
Answer the following questions based on the given c file: #include #include #include    int c...
Answer the following questions based on the given c file: #include #include #include    int c = 0; void *fnC() {     int i;     for(i=0;i<10;i++)     {   c++;         printf(" %d", c);     }       } int main() { int rt1, rt2;   pthread_t t1, t2; int trial_count = 0; // For every trial, lets zero out the counter and run the count routine “twice”     // as threads that can be scheduled onto independent cores instead of running     // in sequence. for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT