Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.15/5 (5 votes)
See more:
Question : Write a program for a restaurant. Your program should display a main menu that allows the customer to select between the breakfast menu option,lunch menu option, dinner menu option and check out option. After selected an option from the main menu, your program should continue to display a sub-menu that will show the available foods and prices for the selected meal.Your program should allow the customer to select the food and enter the order quantity. Your program should continue to allow the customer to order their food until they select the check out option in the main menu,then only your program will display the order list with the quantity, prices and total amount need to pay by the customer.

This is my coding and I need to improve it to display a receipt of items purchased , the total amount need to be paid and allow the user to enter the cash amount they are going to pay and calculate the balance for them. Please help me.




C++
#include <stdio.h>			//header files
#include <ctype.h>
#include <windows.h>

void bfast();		// prototype's
void lunch();
void dinner();
void m_m(); 
void exit();

int num;		//global variable
float price;
float total;
char choice;
int again;

void main()
{
	m_m();
}

 
void m_m()  // main menu screen
{
	char choice = ' ' ; //local variable

  printf("                Welcome to D'10 Restaurant.          \n ");
  printf("             +============================+          \n\n");
  printf("  && Please select the meal that you would like to purchase. && \n\n");
  printf("\t\t      [A] Breakfast\n");
  printf("\t\t      [B] Lunch\n");
  printf("\t\t      [C] Dinner\n");
  printf("\t\t      [D] Exit\n\n");
  printf("Enter your choice here : ");
  scanf("%c", &choice);
  system("cls");
  
		{
		if (toupper(choice) == 'A' )
		  bfast();
		else 
			if (toupper(choice) == 'B')
				  lunch();
			else 
				if (toupper(choice) == 'C')
					  dinner();
				else 
					  if (toupper(choice) == 'D')
						  exit();	
					  else 
						  if (toupper(choice) != 'A' , 'B' , 'C' , 'D')
						  { 
							  m_m();
						  }
	}
  

}
void bfast() //Breakfast Menu Screen 
{
  int choice = 0; //local variables
  int quantity = 0;
  int again = 0;
  
  fflush(stdin);
  printf("                Welcome to D'10 Restaurant.          \n ");
  printf("             +============================+          \n\n");
  printf("                  $  Breakfast Menu  $ \n\n");
  printf("  && Please select the food that you would like to purchase. && \n\n");
  printf("\t\t   [1] Toast - RM 1.00\n");
  printf("\t\t   [2] Egg Muffin - RM 1.50\n");
  printf("\t\t   [3] Nasi Lemak - RM 2.00\n");
  
  
  printf("Enter your choice here : ");
  scanf("%d", &choice);
  {
  if (choice == 1) 
	  {
	  printf("Enter quantity : ");
	  scanf("%d", &quantity);
	  total = 1.00 * quantity ;
	   printf("Your total amount is RM%.2f , Please pay at the counter\n\n\n ", total); 
	   printf("\nWould you like to buy anything else?\n[1] Yes , [2] No : "); // Allows user to choose whether to check-out or buy anything else.
			scanf("%d", &again);
			system("cls");
		
			 if (again == 1 )
				bfast();
			 else 
				 if (again == 2 )
					m_m();
			else
				if (again != 1 , 2)
				{
				 printf("\n\n\t\tSorry Invalid Decision Entered\n\n\n\n");
				 exit();
				}
      }
	else 
		  if ( choice == 2)
		  {
		  printf("Enter quantity : ");
		  scanf("%d", &quantity);
		  total = 1.50 * quantity ;
		  printf("Your total amount is RM%.2f , Please pay at the counter\n\n\n ", total);
		    printf("\nWould you like to buy anything else?\n[1] Yes , [2] No : "); // Allows user to choose whether to check-out or buy anything else.
			scanf("%d", &again);
			system("cls");
		
			 if (again == 1 )
				bfast();
			 else if (again == 2 )	
				m_m();
			else
				if (again != 1 , 2)
				{
				 printf("\n\n\t\tSorry Invalid Decision Entered\n\n\n\n");
				 exit();
				}
		  }
		  else 
			  if ( choice == 3 )
			  {
			  printf("Enter quantity : ");
			  scanf("%d", &quantity);
			  total = 2.00 * quantity ;
			  printf("Your total amount is RM%.2f , Please pay at the counter\n\n\n ", total); 
		       printf("\nWould you like to buy anything else?\n[1] Yes , [2] No : "); // Allows user to choose whether to check-out or buy anything else.
			   scanf("%d", &again);
			   system("cls");
		
			  if (again == 1 )
				{
				bfast();
				 }
			  else 
				  if (again == 2 )
				{	
				m_m();
				}
				else
				    if (again != 1 , 2)
					{
					 printf("\n\n\t\tSorry Invalid Decision Entered\n\n\n\n");
					 exit();
					}
			  }
			  else 
					if (choice != 1 , 2 , 3 )
						{
						fflush(stdin);
						system("cls");
						printf("\n\n\t\t   Invalid Choice Entered\n\n");
						bfast();
						}
    }			
  }

void lunch() // Lunch Screen Menu
{
  int choice;  //local variables
  int quantity;
  int again;
  

  printf("                Welcome to D'10 Restaurant.          \n ");
  printf("             +============================+          \n\n");
  printf("                   $  Lunch Menu  $ \n\n");
  printf("  && Please select the food that you would like to purchase. && \n\n");
  printf("\t\t   [1] Fried Rice - RM 4.00\n");
  printf("\t\t   [2] Mee Goreng- RM 4.00\n");
  printf("\t\t   [3] Fish Head Curry with Rice - RM 5.00\n");
  
  printf("Enter your choice here : ");
  scanf("%d", &choice);
  {
  if (choice == 1) 
	  {
	  printf("Enter quantity : ");
	  scanf("%d", &quantity);
	  total = 4.00 * quantity ;
	  printf("Your total amount is RM%.2f , Please pay at the counter\n\n\n ", total); 
	  {
		printf("\nWould you like to buy anything else?\n[1] Yes , [2] No : ");
		scanf("%d", &again);
		system("cls");
		if (again == 1 )
			lunch();
		else
			if (again == 2 )
				m_m();
		else
			if (again != 1 , 2)
			{	
			 printf("\n\n\t\tSorry Invalid Decision Entered\n\n\n\n");
			 exit();
			}
		}
      }
	else 
		  if ( choice == 2)
		  {
		  printf("Enter quantity : ");
		  scanf("%d", &quantity);
		  total = 4.00 * quantity ;
		  printf("Your total amount is RM%.2f , Please pay at the counter\n\n\n ", total);
		  {
		printf("\nWould you like to buy anything else?\n[1] Yes , [2] No : ");
		scanf("%d", &again);
		system("cls");
		if (again == 1 )
			lunch();
		else 
			if (again == 2 )
				m_m();
		else
			if (again != 1 , 2)
			{	
			 printf("\n\n\t\tSorry Invalid Decision Entered\n\n\n\n");
			 exit();
			}
		}
		  }
		  else 
			  if ( choice == 3 )
			  {
			  printf("Enter quantity : ");
			  scanf("%d", &quantity);
			  total = 5.00 * quantity ;
			  printf("Your total amount is RM%.2f , Please pay at the counter\n\n\n ", total);
			   {
				printf("\nWould you like to buy anything else?\n[1] Yes , [2] No : ");
				scanf("%d", &again);
				system("cls");
				if (again == 1 )
					lunch();
				else 
					if (again == 2 )
						m_m();
				else
					if (again != 1 , 2)
					{	
					 printf("\n\n\t\tSorry Invalid Decision Entered\n\n\n\n");
					 exit();
					}
	           }
			  }

				 else 
					 if (choice != 1 , 2 , 3)
						{
						fflush(stdin);
						system("cls");
						printf("\n\n\t\t   Invalid Choice Entered\n\n");
						lunch();
						}
	  }
				 
  
			
		
}





void dinner() // Dinner Menu Screen
{
  int choice;  //local variables
  int quantity;
  int again;
  

  printf("                Welcome to D'10 Restaurant.          \n ");
  printf("             +============================+          \n\n");
  printf("                    $  Dinner Menu  $ \n\n");
  printf("  && Please select the food that you would like to purchase. && \n\n");
  printf("\t\t   [1] Chicken Chop - RM 6.50\n");
  printf("\t\t   [2] Spagetti - RM 5.50\n");
  printf("\t\t   [3] Chicken Burger - RM 3.00\n");
  
  printf("Enter your choice here : ");
  scanf("%d", &choice);
  {
  if (choice == 1) 
	  {
	  printf("Enter quantity : ");
	  scanf("%d", &quantity);
	  total = 6.50 * quantity ;
	  printf("Your total amount is RM%.2f , Please pay at the counter\n ", total); 
	    {
		printf("\nWould you like to buy anything else?\n[1] Yes , [2] No : ");
		scanf("%d", &again);
		system("cls");
		if (again == 1 )
			dinner();
		else 
			if (again == 2 )
				m_m();
		else
			if (again != 1 , 2)
			{	
			 printf("\n\n\t\tSorry Invalid Decision Entered\n\n\n\n");
			 exit();
			}
			
	    }
      }
	else 
		  if ( choice == 2)
		  {
		  printf("Enter quantity : ");
		  scanf("%d", &quantity);
		  total = 5.50 * quantity ;
		  printf("Your total amount is RM%.2f , Please pay at the counter\n ", total);
		    {
			printf("\nWould you like to buy anything else?\n[1] Yes , [2] No : ");
			scanf("%d", &again);
			system("cls");
			if (again == 1 )
				dinner();
			else 
				if (again == 2 )
					m_m();
			else
				if (again != 1 , 2)
				{	
				 printf("\n\n\t\tSorry Invalid Decision Entered\n\n\n\n");
				 exit();
				}		
	        }
		  }
		  else 
			  if ( choice == 3 )
			  {
			  printf("Enter quantity : ");
			  scanf("%d", &quantity);
			  total = 3.00 * quantity ;
			  printf("Your total amount is RM%.2f , Please pay at the counter\n\n\n ", total);
			    {
				printf("\nWould you like to buy anything else?\n[1] Yes , [2] No : ");
				scanf("%d", &again);
				system("cls");
				if (again == 1 )
					dinner();
				else 
					if (again == 2 )
						m_m();
				else
					if (again != 1 , 2)
					{	
					 printf("\n\n\t\tSorry Invalid Decision Entered\n\n\n\n");
					 exit();
					}
			
				 }
			  }

				 else 
					 if (choice != 1 , 2 , 3)
						{
						fflush(stdin);
						system("cls");
						printf("\n\n\t\t   Invalid Choice Entered\n\n");
						dinner();
						}
		 }		
		
}

void exit()  // Exit Screen
{
  
  printf("                  Thank You Very Much          \n ");
  printf("             +============================+          \n\n");
  printf("               && Please come again. && \n\n");


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 13-Jul-23 16:36pm
v2
Comments
OriginalGriff 6-Jan-14 8:54am    
What part is giving you difficulty?
What have you tried, and where are you stuck?
I know you want to "improve it to display a receipt of items purchased..." and so forth, but I don't know why that is giving you a problem!
[no name] 6-Jan-14 8:58am    
I am stuck at the part where I couldnt calculate the grand total amount. How do I apply it to the program. Kinda confused with it
KarstenK 12-Dec-16 12:42pm    
use some more sub routines to clean up the code. And some constants or defines.

It often helps to see clearer what to do in such a mess ;-)

1 solution

"I am stuck at the part where I couldn't calculate the grand total amount. How do I apply it to the program. Kinda confused with it"


Well, you are merrily calculating totals and displaying them - so why not use them? It wouldn't be a major change to make each function return it's total to your main function and use it there to get the payment. You know how to return a value from a function, don't you?

A couple of other things spring to mind:
1) That really isn't user friendly!
C++
if (again != 1 , 2)
{
 printf("\n\n\t\tSorry Invalid Decision Entered\n\n\n\n");
 exit();
}
Exiting your program because he hit the wrong key is going to be rather annoying for those with fat fingers! :laugh:
2) Altough it is technically correct to write your if..then..else..if... code with that indentation, it does make it very hard to read.
C++
if (toupper(choice) == 'A')
    bfast();
else
    if (toupper(choice) == 'B')
        lunch();
    else
        if (toupper(choice) == 'C')
            dinner();
        else
            if (toupper(choice) == 'D')
                exit();
            else
                if (toupper(choice) != 'A' , 'B' , 'C' , 'D')
                    {
                    m_m();
                    }
Instead, put the else and the if on the same row:
C++
if (toupper(choice) == 'A')
    bfast();
else if (toupper(choice) == 'B')
    lunch();
else if (toupper(choice) == 'C')
    dinner();
else if (toupper(choice) == 'D')
    exit();
else if (toupper(choice) != 'A', 'B' , 'C' , 'D')
    {
    m_m();
    }
(and I've not seen that construct in the final if before - does it compile?)
I'd actually change it and use a switch instead:
C#
switch (toupper(choice))
    {
    case 'A':
        bfast();
        break;
    case 'B':
        lunch();
        break;
    case 'C':
        dinner();
        break;
    case 'D':
        exit();
    default:
        m_m();
        break;
    }
 
Share this answer
 
Comments
[no name] 6-Jan-14 9:18am    
So if I use switch case it would be easier?
OriginalGriff 6-Jan-14 9:33am    
Easier to read! :laugh:
It generates pretty much the same code when it's compiled (although a switch can be a lot, lot more efficient in some cases) - but it is a lot easier to read, and the toupper(choice) bit is only done once which is more efficient anyway.
KarstenK 17-Oct-19 2:59am    
Your code wont stand any code review in my company if you dont use these tips :-O

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900