This needs to be in the c++ language if you can help me out i would appriciate i
ID: 3728074 • Letter: T
Question
This needs to be in the c++ language if you can help me out i would appriciate it very much. thank you.
Select snack items according to the menu provided below.
a) Display a menu.
1) Chips
2) Gummies
3) Pretzels
0) Exit (Zero to exit)
b) Request one integer for a snack item.
c) Validate the input value.
d) Handle the menu with a switch statement or if/else to display the price based on the following:
1) Chips - $1.50
2) Gummies - $1.25
3) Pretzels - $1.00
e) End the program only if Exit option is selected.
f) Display the total amount of lunch items ordered in the transaction.
Explanation / Answer
#include <iostream>
using namespace std;
int main() {
// Displaying menu
cout << "1) Chips " <<endl;
cout << "2) Gummies" << endl;
cout << "3) Pretzels" << endl;
cout << "0) Exit (Zero to exit)" << endl;
int snack;
cin >> snack;
// validating input for snack
// for chips
if(snack== 1 )
{
cout << "Chips - $1.50";
int chips;
cout << endl << "How many chips do you want? ";
cin >> chips;
cout << "Total amount is $" << chips*1.50;
}
// for Gummies
else if(snack== 2)
{
cout << "Gummies - $1.25";
int Gummies;
cout << endl << "How many Gummies do you want? ";
cin >> Gummies;
cout << "Total amount is $" << Gummies*1.25;
}
// for Pretzels
else if(snack== 3)
{
cout << "Pretzels - $1.00";
int Pretzels;
cout << endl << "How many Pretzels do you want? ";
cin >> Pretzels;
cout << "Total amount is $" << Pretzels*1.0;
}
else if(snack== 0)
{
cout << "Exiting...";
}
else
{
cout << "Invalid Input";
}
}
/*
SAMPLE OUTPUT 1
1) Chips
2) Gummies
3) Pretzels
0) Exit (Zero to exit)
1
Chips - $1.50
How many chips do you want? 10
Total amount is $15
SAMPLE OUTPUT 2
1) Chips
2) Gummies
3) Pretzels
0) Exit (Zero to exit)
2
Gummies - $1.25
How many Gummies do you want? 10
Total amount is $12.5
SAMPLE OUTPUT 3
1) Chips
2) Gummies
3) Pretzels
0) Exit (Zero to exit)
3
Pretzels - $1.00
How many Pretzels do you want? 10
Total amount is $10
SAMPLE OUTPUT 4
1) Chips
2) Gummies
3) Pretzels
0) Exit (Zero to exit)
0
Exiting...
SAMPLE OUTPUT 5
1) Chips
2) Gummies
3) Pretzels
0) Exit (Zero to exit)
8
Invalid Input
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.