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]
8 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]8 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
Consider the following method, inCommon, which takes two Integer ArrayList parameters. The method returns true if the same integ
sp2606 [1]

Answer:

The answer is "Option b".

Explanation:

In the given code, a static method "inCommon" is declared, that accepts two array lists in its parameter, and inside the method two for loop is used, in which a conditional statement used, that checks element of array list a is equal to the element of array list b. If the condition is true it will return the value true, and if the condition is not true, it will return a false value. In this, the second loop is not used because j>0 so will never check the element of the first element.

6 0
3 years ago
The command to delete all the files that have filenames that starts with letter c or c and ends with a letter z or z is
dimaraw [331]
The command is : <span>rm [Aa]*[Zz] </span>
4 0
3 years ago
An operating system is defined as hardware that converts software into a useful form for applications.
marissa [1.9K]

Hardware that transforms software into a form that is helpful for applications is referred to as an operating system. False. Hardware conversion is done by software.

<h3>What is an operating system?</h3>
  • Computer hardware and software resources are managed by an operating system (OS), which also offers common functions for software programs.
  • Operating systems that use time-sharing plan activities to make the most of the system's resources.
  • They may also contain accounting software to allocate costs for processing time, mass storage, printing, and other resources.
  • An operating system (OS) is a piece of software that controls all of the other application programs in a computer after being originally loaded by a boot program.
  • Through a specified application program interface, the application programs seek services from the operating system (API).

To learn more about operating system, refer to:

brainly.com/question/22811693

#SPJ4

4 0
1 year ago
Percentage-wise, which renewable energy source is used most?
Natasha2012 [34]
C)Hydroelectric I believe.
5 0
3 years ago
​What file system below does not support encryption, file based compression, and disk quotas, but does support extremely large v
Elena L [17]

Answer:

D.  ReFS

Explanation:

File system is simply a management system for files that controls how and where data are stored, where they can be located and how data can be accessed. It deals with data storage and retrieval.

Examples of file system are NTFS, FAT(e.g FAT 16 and FAT 32), ReFS.

ReFS, which stands for Resilient File System, is designed primarily to enhance scalability by allowing for the storage of extremely large amounts of data and efficiently manage the availability of the data. It is called "resilient" because it ensures the integrity of data by offering resilience to data corruption. It does not support transaction, encryption, file based compression, page file and disk quotas, to mention a few.

6 0
2 years ago
Other questions:
  • Hudson has to maintain confidential college data in a workbook. He needs two team members to help him update data in the specifi
    7·2 answers
  • Name three types of data stored on a computer’s hard disk
    11·1 answer
  • Consider relations A and B. Relation A represents the entity on the ""one side"" of a one-to-many relationship; Relation B repre
    11·1 answer
  • Stealing passwords by using software code to run through various password schemes with numbers, symbols, capital letters, and ch
    6·1 answer
  • There is an application which inputs hundred numbers from the user, if user enters a positive number it increments valid numbers
    6·1 answer
  • When adopting the use of social media in emergency management, it is important to have
    10·1 answer
  • Please help me. Adnan also wants to add a photograph of a bridge. It is on another PowerPoint presentation that is open in a dif
    11·1 answer
  • Including the word OR will make a search less specific.<br> O False<br> O True
    8·2 answers
  • Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending order. The input
    5·1 answer
  • you have been using snmp on your network for monitoring and management. you are concerned about the security of this configurati
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!