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
zaharov [31]
3 years ago
5

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 is gr_apples, output should be:
Computers and Technology
2 answers:
kenny6666 [7]3 years ago
5 0
According to your syntax, I am pretty sure that this one is C++ question. I think that your solution looks like this:
So if useritem is gr_apples, output should be "Fruit".
int main() {   enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};
   GroceryItem userItem = GR_APPLES; if((userItem == GR_APPLES) || (userItem == GR_BANANAS)){ cout << "Fruit"; } else if((userItem == GR_JUICE) || (userItem == GR_WATER)){ cout << "Drink"; } else{ cout << "Unknown"; }
cout << endl;   return 0;}
BartSMP [9]3 years ago
5 0

The given problem can be solved using loops. Compare the user items with given grocery items and print the result whether it is "Fruit", "Drink", or "Unknown".  Here,  enum data structure is used to store the grocery items and if- else loop is used to categorize the grocery items.

Further Explanation:

Code:

The complete C++ code for the given problem is as shown below:

#include <iostream>

using namespace std;

/*Print either "Fruit", "Drink", or "Unknown" depending on the inputs*/

int main() {

enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};

GroceryItem userItem = GR_APPLES;

/* The solution goes here  */

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

cout << "Fruit";

}

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

cout << "Drink";

}

else{

cout << "Unknown";

}

cout << endl;

return 0;

}

Output:

Run the program, the output will be look like as below:

Testing with userItem = GR_APPLES

Your output: Fruit

Testing with userItem = GR_JUICE

Your output: Drink

Testing with userItem = 5

Your output: Unknown

Learn more:

1. A company that allows you to license software monthly to use online is an example of ? brainly.com/question/10410011  

2. How does coding work on computers?  brainly.com/question/2257971 

Answer details:

Grade: College Engineering

Subject: Computer Science

Chapter: C++  Programming

Keyword:

C++, input, output, programming, statements,  loops, if, else, statements, newline, useritem, drink, fruits, return 0

You might be interested in
The part of a rocket engine that allows the combustion gases and flames to leave the rocket engine is the
coldgirl [10]
That would be A: Nozzle
6 0
3 years ago
Help a fellow coder and anser these 5 questions
BlackZzzverrR [31]

Answer: yes because it helps

Explanation: it shows everything

4 0
3 years ago
Pros of mobile devices on young people during their free time
Elis [28]
Studies have shown that the people who spend more time on social media are better to show virtual empathy to their online friends 
8 0
3 years ago
Create a class called Clock to represent a Clock. It should have three private instance variables: An int for the hours, an int
Anvisha [2.4K]

Answer:

public class Clock

{

private int hr; //store hours

private int min;  //store minutes

private int sec; //store seconds

public Clock ()

{

 setTime (0, 0, 0);

}

public Clock (int hours, int minutes, int seconds)

{

 setTime (hours, minutes, seconds);

}

public void setTime (int hours, int minutes, int seconds)

{

 if (0 <= hours && hours < 24)

      hr = hours;

 else

      hr = 0;

 

 if (0 <= minutes && minutes < 60)

      min = minutes;

 else

      min = 0;

 

 if (0 <= seconds && seconds < 60)

      sec = seconds;

 else

      sec = 0;

}

 

 //Method to return the hours

public int getHours ( )

{

 return hr;

}

 //Method to return the minutes

public int getMinutes ( )

{

 return min;

}

 //Method to return the seconds

public int getSeconds ( )

{

 return sec;

}

public void printTime ( )

{

 if (hr < 10)

      System.out.print ("0");

 System.out.print (hr + ":");

 if (min < 10)

      System.out.print ("0");

 System.out.print (min + ":");

 if (sec < 10)

      System.out.print ("0");

 System.out.print (sec);

}

 

 //The time is incremented by one second

 //If the before-increment time is 23:59:59, the time

 //is reset to 00:00:00

public void incrementSeconds ( )

{

 sec++;

 

 if (sec > 59)

 {

  sec = 0;

  incrementMinutes ( );  //increment minutes

 }

}

 ///The time is incremented by one minute

 //If the before-increment time is 23:59:53, the time

 //is reset to 00:00:53

public void incrementMinutes ( )

{

 min++;

 

if (min > 59)

 {

  min = 0;

  incrementHours ( );  //increment hours

 }

}

public void incrementHours ( )

{

 hr++;

 

 if (hr > 23)

     hr = 0;

}

public boolean equals (Clock otherClock)

{

 return (hr == otherClock.hr

  && min == otherClock.min

   && sec == otherClock.sec);

}

}

3 0
3 years ago
I need help here thanks forever who helps
lubasha [3.4K]

Answer:

the horse, the man, and the cactus

Explanation:

The horse is running

The man got slung off the horse, so its in motion

The cactus is flying everywhere from the horse.

3 0
2 years ago
Other questions:
  • I only want someones opinion on this not anything you would find in a book.
    7·1 answer
  • A ________ is a container that provides quick access to elements at the front and the back of the list
    6·1 answer
  • The Start menu on Windows computers changes based on actions performed by their users. True False
    15·2 answers
  • Consider a system consisting of m resources of the same type, being shared by n processes. Resources can be requested and releas
    9·1 answer
  • PLZ HELP
    15·2 answers
  • What is LINUX?
    6·2 answers
  • 8. A sprite is a simple spider shaped thing with n legs coming out from a center point. The angle
    10·1 answer
  • In this program you will read in the number of seconds and convert it to days, hours, minutes and remaining seconds.
    8·1 answer
  • If a company gave you a free version of their software and encouraged you to try and improve it and share it with the only commu
    8·1 answer
  • The entities on which data are collected are _____.
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!