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:Fruit#include int main(void) {enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};enum GroceryItem userItem = GR_APPLES;/* Your solution goes here */return 0;}

Respuesta :

Answer:

Here is the complete code

#include <iostream>  //for input output functions

using namespace std;   //to identify objects like cin cout

int main() {  //start of main() function body

  enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};  //enum is used to assign names to constant

  GroceryItem userItem = GR_APPLES;  

//value of userItem is set to GR_APPLES

  /* Your solution goes here  */

//if the userItem is equal to GR_APPLES or GR_BANANAS

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

 cout << "Fruit";  } //display Fruit if above if condition is true

//if the value of userItem is equal to GR_JUICE or GR_WATER

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

 cout << "Drink";  } //display Drink if the above if condition is true

else{  //if none of the above if conditions is true then print Unknown

 cout << "Unknown";  }  

cout << endl;

  return 0;  }

Explanation:

The output of the program is Fruit because the value of userItem is set to GR_APPLES and according to the if statement if the userItem is equal to GR_APPLES than "Fruit" will be displayed on the screen as output.

The program along with its output is attached as a screen shot.

Ver imagen mahamnasir