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

Fruit

#include <stdio.h>

int main(void) {
enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};

enum GroceryItem userItem = GR_APPLES;

/* Your solution goes here */

return 0;
}

USE C PLEASE

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

Executable code:

C code:

#include

#include

int main()

{

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

GroceryItem userItem = GR_APPLES;

//switching into the user Input

switch(userItem)

{

//switch cases for fruits

case GR_APPLES:

case GR_BANANAS:

printf("Fruit\n");

break;

//switch cases for drinks

case GR_JUICE:

case GR_WATER:

printf("Drink\n");

break;

//default case called unknown

default : printf("Unknown\n");

break;

}

system("pause");

return 0;

}

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.

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