我需要为一家餐馆写一个程序。使用C.需要添加一些项目 [英] I need to write a Program for a restaurant. Using C. Need to add some items

查看:82
本文介绍了我需要为一家餐馆写一个程序。使用C.需要添加一些项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:为餐馆写一个程序。您的程序应显示主菜单,允许客户在早餐菜单选项,午餐菜单选项,晚餐菜单选项和结账选项之间进行选择。从主菜单中选择一个选项后,您的程序应继续显示一个子菜单,该子菜单将显示所选食物的可用食物和价格。您的程序应允许客户选择食物并输入订单数量。您的程序应继续允许客户订购他们的食物,直到他们选择主菜单中的结帐选项,然后只有您的程序将显示订单列表,其中包含客户需要支付的数量,价格和总金额。 />


这是我的编码,我需要改进它以显示购买物品的收据,需要支付的总金额并允许用户输入现金金额要支付并计算他们的余额。请帮帮我。









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.




#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]已添加代码块 - OriginalGriff [/ edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

早餐菜单


\ n\ n);
printf( &&请选择您想要购买的食物。&& \\\
\ 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( 在此处输入您的选择:);
scanf( % d,& choice);
{
if (choice == 1
{
printf( 输入数量:);
scanf( %d,& quantity);
total = 1 00 *数量;
printf( 您的总金额为RM%.2f,请在柜台付款\ n \ n \ n,总计);
printf( \\\
你想买别的吗?\ n [1]是的,[ 2]否:
); // 允许用户选择是否退房或购买其他任何东西。
scanf( %d,& again);
system( cls);

if (再次== 1
bfast() ;
else
if (再次== 2
m_m();
else
if (再次!= 1 2
{
printf( \ n \ n \\\ t \ tSorry无效的决定已输入\ nn \ n \\ n
exit();
\t\t\t\t}
}
\telse
\t\t if ( choice == 2)
\t\t {
\t\t printf(\"Enter quantity : \");
\t\t scanf(\"%d\", &quantity);
\t\t total = 1.50 * quantity ;
\t\t printf(\"Your total amount is RM%.2f , Please pay at the counter\n\n\n \", total);
\t\t 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.
\t\t\tscanf(\"%d\", &again);
\t\t\tsystem(\"cls\");
\t\t
\t\t\t if (again == 1 )
\t\t\t\tbfast();
\t\t\t else if (again == 2 )\t
\t\t\t\tm_m();
\t\t\telse
\t\t\t\tif (again != 1 , 2)
\t\t\t\t{
\t\t\t\t printf(\"\n\n\t\tSorry Invalid Decision Entered\n\n\n\n\");
\t\t\t\t exit();
\t\t\t\t}
\t\t }
\t\t else
\t\t\t if ( choice == 3 )
\t\t\t {
\t\t\t printf(\"Enter quantity : \");
\t\t\t scanf(\"%d\", &quantity);
\t\t\t total = 2.00 * quantity ;
\t\t\t printf(\"Your total amount is RM%.2f , Please pay at the counter\n\n\n \", total);
\t\t 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.
\t\t\t scanf(\"%d\", &again);
\t\t\t system(\"cls\");
\t\t
\t\t\t if (again == 1 )
\t\t\t\t{
\t\t\t\tbfast();
\t\t\t\t }
\t\t\t else
\t\t\t\t if (again == 2 )
\t\t\t\t{\t
\t\t\t\tm_m();
\t\t\t\t}
\t\t\t\telse
\t\t\t\t if (again != 1 , 2)
\t\t\t\t\t{
\t\t\t\t\t printf(\"\n\n\t\tSorry Invalid Decision Entered\n\n\n\n\");
\t\t\t\t\t exit();
\t\t\t\t\t}
\t\t\t }
\t\t\t else
\t\t\t\t\tif (choice != 1 , 2 , 3 )
\t\t\t\t\t\t{
\t\t\t\t\t\tfflush(stdin);
\t\t\t\t\t\tsystem(\"cls\");
\t\t\t\t\t\tprintf(\"\n\n\t\t Invalid Choice Entered\n\n\");
\t\t\t\t\t\tbfast();
\t\t\t\t\t\t}
}\t\t\t
}

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


printf(\" Welcome to D'10 Restaurant. \n \");
printf(\" +============================+ \n\n\");
printf(\"
\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


这篇关于我需要为一家餐馆写一个程序。使用C.需要添加一些项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆