Print either "fruit", "drink", or "unknown" (followed by a newline) depending on the value of useritem. print "unknown" (followed 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:

Respuesta :

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;}

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