1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
HACTEHA [7]
10 months ago
14

Assume that an int variable age has been declared and already given a value. Assume further that the user has just been presente

d 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 the String (S or T or B) that the user types in into a String variable choice that has already been declared and 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.
ASSUME the availability of a variable, stdin, that references a Scanner object associated with standard input.
Instructor Notes:
Hint:

Use .equals for String comparison, e.g.
if (choice.equals("B")) instead of
if (choice == "B") // BAD

You might want to skip this one and do section 3.6 (which covers String comparison) beforehand.
Computers and Technology
1 answer:
Musya8 [376]10 months ago
8 0

Using the knowledge of computational language in C++ it is possible to write a code that assume that an int variable age has been declared and already given a value

<h3>Writting the code:</h3>

<em>#include<stdio.h></em>

<em>#include<conio.h></em>

<em>int main()</em>

<em>{</em>

<em>//variables to rad choice and age</em>

<em>char choice;</em>

<em>int age;</em>

<em>//read age and choice</em>

<em>printf("\tEnter your age: ");</em>

<em>scanf("%d", &age);</em>

<em>//fflush the keyboard buffer before reading choice</em>

<em>fflush(stdin);</em>

<em>printf("\tEnter your choice: ");</em>

<em>scanf("%c", &choice);</em>

<em>//print the invalid message if the choice is otherthan the S,T,B</em>

<em>if(choice!='S' && choice !='T' && choice !='B')</em>

<em>{</em>

<em>printf("Invalid menu choice");</em>

<em>getch();</em>

<em>}</em>

<em>else if (age <22)</em>

<em>{</em>

<em>if (choice =='S')</em>

<em>{</em>

<em>printf("\tvegetable juice");</em>

<em>}</em>

<em>else if (choice =='T')</em>

<em>{</em>

<em>printf("\tcranberry juice");</em>

<em>}</em>

<em>else if (choice == 'B')</em>

<em>{</em>

<em>printf("\tsoda");</em>

<em>}</em>

<em>}</em>

<em>else</em>

<em>{</em>

<em>if (choice == 'S')</em>

<em>{</em>

<em>printf("\tcabernet");</em>

<em>}</em>

<em>else if (choice =='T')</em>

<em>{</em>

<em>printf("\tchardonnay");</em>

<em>}</em>

<em>else if (choice == 'B')</em>

<em>{</em>

<em>printf("\tIPA");</em>

<em>}</em>

<em>}</em>

<em>//pause the console output until user press any key on keyboard</em>

<em>getch();</em>

<em>}</em>

See more about C++ at brainly.com/question/19705654

#SPJ1

You might be interested in
According to the video, what is used to create computer programs?
Lena [83]
Its a or b. znskdbxkdb
8 0
3 years ago
Read 2 more answers
What do work places allow a company to do
anygoal [31]
D. They provide a platform for collaboration
8 0
3 years ago
Which of the following statements best compares and contrasts hot and cold type?
Elina [12.6K]

Answer:

3 text 3

Explanation:

7 0
2 years ago
Windows workstations all have elements of server software built-in. What are these elements, and why is the Windows Professional
lions [1.4K]

Answer:

The answer is below

Explanation:

Elements of Server software that is built-in, in Windows workstations are:

1. Hard drives,

2. RAM (Random Access Memory)

3. Processors

4. Network adapters.

Windows Professional OS is not considered a server due to the following:

1. Windows Professional OS has a limit on the number of client connections it allowed.

2. Unlike Server, Professional OS uses less memory

2. In comparison to Server, Professional OS uses the CPU less efficiently

4. Professional OS is not built to process background tasks, unlike Server that is configured to perform background tasks.

6 0
3 years ago
write a function that returns a list, where each member of list contains previous day’s value multiplied by 2.​
sergeinik [125]

Answer:

Explanation:

The following code is written in Java, the function takes in a list with the previous day's values. The function then uses that list, loops through it and multiplies each individual value by 2 and returns the modified list. The first red  square represents the test case for the function, while the second red square in the image represents the output.

 public static ArrayList<Integer> doubleIt(ArrayList<Integer> mylist) {

       for (int x = 0; x<mylist.size(); x++) {

           mylist.set(x, mylist.get(x)*2);

       }

       return mylist;

   }

5 0
3 years ago
Other questions:
  • Driving while wearing headphones or earphones
    12·2 answers
  • In which step of writing a program does a programmer first use a<br> compiler?<br> documentin
    6·1 answer
  • A teacher takes the following steps when beginning to apply conditional formatting to a spreadsheet. Format Conditional Formatti
    8·1 answer
  • A file named numbers.txt contains an unknown number of lines, each consisting of a single positive integer. Write some code that
    6·1 answer
  • Joe runs a handyman service. He enjoys writing and keeping up on the latest trends. He wants to share this information with his
    14·1 answer
  • The valid call to the function installApplication is
    5·1 answer
  • Here is a nested loop example that graphically depicts an integer's magnitude by using asterisks, creating what is commonly call
    7·1 answer
  • Rate my dog out of ten give explanation why
    12·1 answer
  • In fnaf who´s spring trap in fnaf 3 and who are the five victim names that he murdered and lure them into the back room.
    10·2 answers
  • Javed’s teacher tells him she would like to see him improve his speaking skills in the next debate by including a rhetorical app
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!