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]
9 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]9 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
The __________ statement allows you to check for
sweet [91]

Answer:

B) nested if...else

Explanation:

In Computer programming, there are four (4) main types of statements used in the decision-making process and these are;

I. If statement.

II. If....else statement.

III. Else.....if statement.

IV. Nested if...else statement.

The nested if...else statement allows you to check for multiple test expressions and execute different codes for more than two conditions. It uses the other three (3) statements in its decision-making process.

However, only the first test expression would be executed when it is true and then the program is terminated. Otherwise, the program would continue to run until it gets to the breaking point (else statement) and then terminates.

3 0
2 years ago
To print the number of elements in the array named ar, you can write :
Diano4ka-milaya [45]

Answer:

Option c is correct.

Example :

public class Subject

{

public static void main(String [] args)

{

int ar[]={5,4,6,7,8};

System.out.println("the number of array elements are: ",ar.length);

}

}

Explanation:

The above program is created in java language in which Subject is a class name.Inside Subject class , there is main method.

Inside the main method, there is An array named 'ar' which data type is an integer and we have assigned the value to this array.

in the next line, we are printing the total no. of the element in the array with the length function which displays the length of an array or variable.

8 0
3 years ago
Speech on inventors and inventions
vlada-n [284]
Interntors present an interesting kind of people who think in peculiar ways sometimes. This ability allows them to view certain situations in ways in which other people cannot. Because of this, they can think of new ways of how such situations can be tackled. This is how inventions are born. A person with an inventive mind sees a new situation where he thinks of a new solution how he could improve this situation with his invention.

This process is continued continuously with new generations of inventors seeing and coming back to old situations over and over again, inventing new things along the way. 
4 0
3 years ago
Which of the following is not a negative environmental effect associated with cars? A. Deforestation B. Roadside litter C. Toxic
777dan777 [17]

Answer:

The answer to this question is the option "C".

Explanation:

In this question, the answer is option C. Which is river toxic pollution. This pollution is also known as Kim Kim river toxic pollution. In 2019 this pollution occurred in the water caused by unauthorized chemical garbage dumping in the river in Malaysia. The unauthorized dumping released poisonous fumes, affecting six thousand people are hospitalized in 2,775.

8 0
3 years ago
what is the molarity of a solution prepared by dissolving 15.0g of sodium hydroxide in enough water to make a total of 225 ml of
Reptile [31]

Answer:

1.6666 g/mol = 1 \frac{2}{3} g/mol

Explanation:

Molar mass of NaOH= 23+16+1 =40g/mol

Mols in 15g = 15/40 mol

If this was dissolved in 225ml of water molarity of the solution is

\frac{15}{40} ÷ 225 x 1000 = 1.6666 g/mol = 1 \frac{2}{3} g/mol

5 0
3 years ago
Other questions:
  • Regulatory control limits the activities of an organization in compliance with the organization's policies. True False
    14·2 answers
  • Which of the following is NOT an ethical way of getting to the top of a web search?
    5·1 answer
  • What are some useful properties of current electricity
    13·2 answers
  • Ben pays his mobile bills, watches movies, and shops online using the Internet. Which internet activity does he perform?
    13·2 answers
  • How can you tell that a spreadsheet was saved as a 2007 Excel file?
    7·1 answer
  • William is an HR manager in a textile-manufacturing firm. He is creating a file on the hours each employee worked during the las
    6·2 answers
  • Which of the following does not represent the function of a Variable? Variables store data in memory; this data has limited use
    8·1 answer
  • How to fix a light blub
    11·2 answers
  • WILL MARK BRAINLIEST WORTH ALOT OF POINTS! HELP ME GET THIS DONE
    8·1 answer
  • List at least 5 disadvantages caused by computer viruses?​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!