Question

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

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 = GR_APPLES, output should be:

Fruit



Sample 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.)

0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

Program Code portion screen shot:

Progam Code Screen Shot:

Sample Output:

Program code portion to copy:

// Declare the main function

int main()

{

       // Declare the enum of fruits

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

       // Declare the Grocery Item

       GroceryItem userItem = GR_APPLES;

       switch (userItem)

       {

       // Declare the case of GR Apples

       case GR_APPLES:

       // Declare the case of GR BANANAS

       case GR_BANANAS: cout << "Fruit";

              cout << endl;

              break;

       // Declare the case of GR Juice

       case GR_JUICE:

       // Declare the case of GR_WATER

       case GR_WATER: cout << "Drink";

              cout << endl;

              break;

       // Declre the by default case

       default: cout << "Unknown";

              cout << endl;

              break;

       }

       // system pause to hold the screen

       system("pause");

       // return the element.

       return 0;

}

Program code to copy:

// Header file require only in Viual studio

#include "stdafx.h"

//Required header files.

//Include the iostream header file for

//input oputput operations.

#include

// Define the name space of the program

using namespace std;

// Declare the main function

int main()

{

       // Declare the enum of fruits

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

       // Declare the Grocery Item

       GroceryItem userItem = GR_APPLES;

       switch (userItem)

       {

       // Declare the case of GR Apples

       case GR_APPLES:

       // Declare the case of GR BANANAS

       case GR_BANANAS: cout << "Fruit";

              cout << endl;

              break;

       // Declare the case of GR Juice

       case GR_JUICE:

       // Declare the case of GR_WATER

       case GR_WATER: cout << "Drink";

              cout << endl;

              break;

       // Declre the by default case

       default: cout << "Unknown";

              cout << endl;

              break;

       }

       // system pause to hold the screen

       system("pause");

       // return the element.

       return 0;

}

Add a comment
Answer #2

#include <stdio.h>


int main() {

  

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

  

  enum GroceryItem userItem;

  

  userItem = GR_APPLES;

  

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

    

    printf("Fruit\n");

    

  }

  

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

    

    printf("Drink\n");

    

  }

  

  else{

    

    printf("Unknown\n");

    

  }

  

  return 0;

  

}



answered by: codegates
Add a comment
Know the answer?
Add Answer to:
Print either "Fruit", "Drink", or "Unknown" (followed by a newline) depending on the value of userItem....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT