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
kupik [55]
3 years ago
15

Print either "Fruit", "Drink", or "Unknown" (followed by a newline) depending on the value of userItem. Print "Unknown" (followe

d by a newline) if the value of userItem does not match any of the defined options. For example, if userItem = GR_APPLES, output should be:FruitSample program:#include using namespace std;int main() { enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER}; GroceryItem userItem = GR_APPLES; return 0;}Below, do not type an entire program. Only type the portion indicated by the above instructions (and if a sample program is shown above, only type the portion.)

Computers and Technology
1 answer:
vagabundo [1.1K]3 years ago
7 0

Answer:

I am writing a C++ program. Let me know if you want the program in some other programming language. Here is the portion of the code:

if((userItem == GR_APPLES) || (userItem == GR_BANANAS)){

 cout << "Fruit";   }

else if((userItem == GR_JUICE) || (userItem == GR_WATER)){

 cout << "Drink";  }

else{

 cout << "Unknown";  }  

cout << endl;

 

Explanation:

The IF statement is used to check the defined options with the value in the userItem.

If the value of the userItem is GR_APPLES OR GR_BANANAS then Fruit is printed as the output. || represents a logical operator OR so this means that userItem can be either the GR_APPLES or GR_BANANAS for the If condition to evaluate to true.

If the above condition evaluates to false then the else-if part will be checked next. So the else if checks if the value in the userItem is GR_JUICE or GR_WATER. If userItem contains either of these two then Drink is displayed on the screen as output.

If the else-if statement also evaluates to false then the else part is executed which displays Unknown.

The cout<< endl; statement in the last is used to print the new line. For example if the output is Unknown then it is followed by a new line.

In the given program userItem is set to GR_APPLES

GroceryItem userItem = GR_APPLES

So the output of the whole program is Fruit followed by a new line.

The screenshot of the code along with the output is attached.

You might be interested in
How can development in ICT be utilized to speed up the development and integration efforts
maw [93]

Answer:

Explanation:

1.  Sustainability and scale

2.  Lack of knowledge

 

3. Pace of change

4.  Funding

5. Changing roles and norms

7 0
3 years ago
Can you explain why you got the error message when trying to use the command x = c\d
ASHA 777 [7]
Do You mean x= x / d   ?....because there is no " \ " in math operations
6 0
3 years ago
Which of the following best describes open source software?
sp2606 [1]
What was the options they gave you?
5 0
3 years ago
Read 2 more answers
What are the charactaristic of computer with virus​
NISA [10]

Explanation:

One of the main characteristics of computer viruses is related to the fact that they are programs created by hackers that attack the code of a computer, infecting files on the computer's hard drive or its source code. Once the virus has been copied onto the computer, it can contaminate other computers that come into contact with the machine.

5 0
3 years ago
Read 2 more answers
What helps maintain the proper function of a wireless token ring
Usimov [2.4K]

Answer:

I believe the answer is beckoning.

3 0
3 years ago
Other questions:
  • Which is an example of correct HTML?
    10·1 answer
  • : For each of the following words identify the bytethat is stored at lower memory address and the byte that is storedat higher m
    6·1 answer
  • Heelo how do u do python syntax lesson 11 on code academy
    12·1 answer
  • My friend Leo wants to have an emergency plan for his final exams on University of Southern Algorithmville. He has N subjects to
    6·1 answer
  • If your microwave oven is a computer, define its Operating System and User Interface.
    12·1 answer
  • Can anyone help me with these assignments??? Hands On Assignments- Insertion of Symbols, Special Characters, and Images.... and
    9·1 answer
  • Another way to create a new presentation is from the Home tab
    6·2 answers
  • What are the pieces of information that describe the appearance of a cells content
    6·1 answer
  • which one of the following will reach every element in the array a? 1. for(int i = 0; i &lt;= a.length; i++) 2. for(int i = 0; i
    10·1 answer
  • How do you modify WordArt? Give specific details and steps<br><br> NEED THIS ASAP
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!