Question

C++ You will have to write a simple food kiosk menu, and allow the user to...

C++


You will have to write a simple food kiosk menu, and allow the user to enter different options to make a purchase. Every option generates a different response from the kiosk. The program starts by printing the following menu:

Please select a menu item from the list below: 
1 – View food menu
2 – Pay total due
3 – Add $5 in credit
4 – Clear order

The user can input a numerical menu option between 1 and 4. If an incorrect entry is inputted then the program will print.

Please enter a valid option!

Below is an explanation of each menu option:

  • 1 – View food menu: This option will go into another menu which will display food options to the user. The user can input a numerical menu option between 1 and 5.
What would you like to add to your order?
(1) Chicken Sandwich: $3.45
(2) Chicken Salad: $4.00
(3) French Fries: $1.99
(4) Hotdog: $2.99
(5) Pizza: $3.99
(6) Go to main menu
Your current total is: $0.00

If an incorrect entry is inputted then the program will print.

Invalid item number please try again

This menu will loop until the user enters option 6 which will bring them back to the main menu. When the user inputs an option between 1 and 5 the program will display a confirmation of the selected item. Make sure that each corresponding menu option prints the exact confirmation format listed below:

You have added a Chicken Sandwich to your order.
You have added a Chicken Salad to your order.
You have added French Fries to your order.
You have added a Hot Dog to your order.
You have added a Slice of Pizza to your order.

Below is an example of the console output when the user chooses option 1 and then 2 (note that the input is not visible in the output).

What would you like to add to your order?
(1) Chicken Sandwich: $3.45
(2) Chicken Salad: $4.00
(3) French Fries: $1.99
(4) Hotdog: $2.99
(5) Pizza: $3.99
(6) Go to main menu
Your current total is: $0.00

You have added a Chicken Sandwich to your order.
What would you like to add to your order?
(1) Chicken Sandwich: $3.45
(2) Chicken Salad: $4.00
(3) French Fries: $1.99
(4) Hotdog: $2.99
(5) Pizza: $3.99
(6) Go to main menu
Your current total is: $3.45

You have added a Chicken Salad to your order.
What would you like to add to your order?
(1) Chicken Sandwich: $3.45
(2) Chicken Salad: $4.00
(3) French Fries: $1.99
(4) Hotdog: $2.99
(5) Pizza: $3.99
(6) Go to main menu
Your current total is: $7.45
  • 2 – Pay total due: This option allows the user to pay the amount that is due. The user will start from an initial budget of $10 and if the user is able to afford the total due then the purchase will go through and the user will see the following text:
Your total due is: $7.45
Thank you! Your change is: $2.55
Enjoy your meal!

If the user cannot afford the purchase they will received the following console text and exit the program:

Insufficient funds!
  • 3 - Add $5 in credit: This option increments the available credit by $5, and prints the new available credit (with 2 digits precision):
Credit available: $<credit>
  • 4 – Clear order: This menu option will reset the total balance due to $0:
Current order balance has been cleared. Current due: $0.00 

Below is an example of what the program should output based on the input 1 3 5 6 2.

Please select a menu item from the list below
1 - View Food Menu
2 - Pay total due
3 - Add $5 in credit
4 - Clear order

What would you like to add to your order?
(1) Chicken Sandwich: $3.45
(2) Chicken Salad: $4.00
(3) French Fries: $1.99
(4) Hotdog: $2.99
(5) Pizza: $3.99
(6) Go to main menu
Your current total is: $0.00
You have added French Fries to your order.

What would you like to add to your order?
(1) Chicken Sandwich: $3.45
(2) Chicken Salad: $4.00
(3) French Fries: $1.99
(4) Hotdog: $2.99
(5) Pizza: $3.99
(6) Go to main menu
Your current total is: $1.99
You have selected added a Slice of Pizza to your order

What would you like to add to your order?
(1) Chicken Sandwich: $3.45
(2) Chicken Salad: $4.00
(3) French Fries: $1.99
(4) Hotdog: $2.99
(5) Pizza: $3.99
(6) Go to main menu
Your current total is: $5.98

Please select a menu item from the list below
1 - View Food Menu
2 - Pay total due
3 - Add $5 in credit
4 - Clear order

Your total due is: $5.98
Thank you! Your change is: $4.02
Enjoy your meal!

Every dollar amount must be printed with 2 digits precision. Check section 9.2 of this book for how to use setprecision and iomanip to achieve this result.

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

/* C++ program that demonstrates the restaurants menu and paying bill. */
//main.c
//include header file
#include<iostream>
#include<iomanip>
using namespace std;
//function prototypes
int menu();
int viewFoodMenu(double &totalpay);
void paybill(double balance, double due);
void addCredit(double &balance);
void clearOrder(double &balance);
//start of main function
int main()
{
   double balance=10;
   double payamount=0;
   int choice;
   //set repeat to true
   bool repeat=true;
   //run loop until repeat is true
   while(repeat)
   {
       choice=menu();
       switch(choice)
       {
       case 1:
           viewFoodMenu(payamount);
           break;
       case 2:
           paybill(balance,payamount);
           //set repeat to false
           repeat=false;

           break;
       case 3:
           addCredit(balance);
           break;
       case 4:
           clearOrder(payamount);
           break;
       }
   }

   //pause program output on console window
   system("pause");
   return 0;
}
//Function to clear order
void clearOrder(double &payamount)
{
   payamount=0;
}
//Function to add credit,5 to balance
void addCredit(double &balance)
{
   const int CREDIT=5;
   balance=balance+CREDIT;
}
//Functioin to choose menu choice
int menu()
{
   int order;
   cout<<"Please select a menu item from the list below"<<endl;
   cout<<"1 - View Food Menu"<<endl;
   cout<<"2 - Pay total due"<<endl;
   cout<<"3 - Add $5 in credit"<<endl;
   cout<<"4 - Clear order"<<endl;
   cin>>order;
   return order;
}
//Function to pay bill amount
void paybill(double balance, double due)
{

   if(balance>due)
   {
       cout<<"Your total due is: $"<<fixed<<setprecision(2)<<due<<endl;
       cout<<"Thank you! Your change is: $"
           <<fixed<<setprecision(2)<<(balance-due)<<endl;
       cout<<"Enjoy your meal!"<<endl;
   }

}
//Function to display the menu
int viewFoodMenu(double &totalpay)
{
   int choice;
   cout<<"What would you like to add to your order?"<<endl;
   cout<<"(1) Chicken Sandwich: $3.45"<<endl;
   cout<<"(2) Chicken Salad: $4.00"<<endl;
   cout<<"(3) French Fries: $1.99"<<endl;
   cout<<"(4) Hotdog: $2.99"<<endl;
   cout<<"(5) Pizza: $3.99"<<endl;
   cout<<"(6) Go to main menu"<<endl;
   cin>>choice;

   if(choice==6)
       return 0;

   switch(choice)
   {
       case 1:
           totalpay=totalpay+3.45;
           cout<<"You have added Chicken Sandwich to your order."<<endl;
           break;
       case 2:
           totalpay=totalpay+4.00;
           cout<<"You have added Chicken Salad to your order."<<endl;
           break;
       case 3:
           totalpay=totalpay+1.99;
           cout<<"You have added French Fries to your order."<<endl;
           break;
       case 4:
           totalpay=totalpay+2.99;
           cout<<"You have added Hotdog to your order."<<endl;
           break;
       case 5:
           totalpay=totalpay+3.99;
           cout<<"You have added Pizza to your order."<<endl;
           break;
   }

   cout<<"Your current total is: $"<<fixed<<setprecision(2)
       <<totalpay<<endl;
}

Sample Output:

Add a comment
Know the answer?
Add Answer to:
C++ You will have to write a simple food kiosk menu, and allow the user to...
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