Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, please help write code in C++. A vending machine serves chips, fruit, nut

ID: 3596149 • Letter: H

Question

Hello, please help write code in C++. A vending machine serves chips, fruit, nuts, juice, water, and coffee. The machine owner wants a daily report indicating what items sold that day. Given boolean values (1 or 0) indicating whether or not at least one of each item was sold, output a list for the owner. If all three snacks were sold, output "All snacks" instead of individual snacks. Likewise, output "All drinks" if appropriate. For coding simplicity, output a space after every item, even the last item.

Explanation / Answer

#include<iostream>
using namespace std;
int main(){
//declare variables
bool chips,fruit,nuts,juice,water,coffee;
//get user input
cout << "Enter 1 for sold or 0 for unsold chips fruit nuts juice water coffee Enter sold or unsold for each:";
cin >> chips;
cin >> fruit;
cin >> nuts;
cin >> juice;
cin >> water;
cin >> coffee;
//print output based on input
if(chips && fruit && nuts){
cout << "All Snacks : 1" << endl;
}
else{
cout << "chips : " << chips << endl;
cout << "fruit : " << fruit << endl;
cout << "nuts : " << nuts << endl;
}
if(juice && water && coffee){
cout << "All drinks : 1" << endl;
}
else{
cout << "juice : " << juice << endl;
cout << "water : " << water << endl;
cout << "coffee : " << coffee << endl;
}
return 0;
}

/*
sample output

Enter 1 for sold or 0 for unsold
chips
fruit
nuts
juice
water
coffee
Enter sold or unsold for each: 1 1 1 1 1 1
All Snacks : 1
All drinks : 1
*/