QUESTION IMAGE
Question
activity 3.10.1: enumerations: grocery items. organize the lines of code to output \fruit\ if the value of useritem is a type of fruit. otherwise, if the value of useritem is a type of drink, output \drink\. otherwise, output \unknown\. ex: if the input is 0, representing named value gr_apples, then the output is: fruit how to use this tool unused else if (useritem == gr_juice || useritem == gr_water) { cout << \unknown\ << endl; cout << \drink\ << endl; cout << \fruit\ << endl; else { } } } if (useritem == gr_apples || useritem == gr_bananas) { main.cpp #include <iostream> using namespace std; int main() { enum groceryitem {gr_apples, gr_bananas, gr_juice, gr_wa_ int useritem; cin >> useritem; return 0; } load default template... full screen zybooks catalog
Step1: Add missing enum member
enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};
Step2: Add fruit check condition
if (userItem == GR_APPLES || userItem == GR_BANANAS) {
cout << "Fruit" << endl;
}
Step3: Reorder logic blocks
Place the fruit check before the drink check, then the else block.
Step4: Complete full code structure
Combine all elements in correct order.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
#include <iostream>
using namespace std;
int main() {
enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};
int userItem;
cin >> userItem;
if (userItem == GR_APPLES || userItem == GR_BANANAS) {
cout << "Fruit" << endl;
}
else if (userItem == GR_JUICE || userItem == GR_WATER) {
cout << "Drink" << endl;
}
else {
cout << "Unknown" << endl;
}
return 0;
}
When input is 0 (GR_APPLES), the output is:Fruit