When you call menu after user input is [1] yes. with menu() function show menu and after menu you should show call food() function.
HERE WHAT YOU WANT
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void menu();
void foods();
void main();
char food;
int quantity;
float price;
float total;
float grandtotal;
int choice;
void main()
{
clrscr();
do {
menu();
foods();
printf("\n Do you want to order more? [1] Yes [2] No:");
scanf("%d", &choice);
getchar(); // <== remove newline
grandtotal = grandtotal + total;
} while (choice == 1);
printf("\n Total Price is: %0.2f", grandtotal);
getch();
}
void menu() {
food = ' ';
quantity = 0;
price = 0;
total = 0;
choice = 0;
printf("Please select food from the following:\n");
printf(" B = Burger, F = French Fries, P = Pizza, S = Sandwiches \n");
printf("Enter food:");
scanf("%c", &food);
}
void foods() {
switch (food)
{
case 'B':
printf("You selected Burger!\n");
printf("Enter quantity:");
scanf("%d", &quantity);
price = 95.50;
//printf("\n Do you want to order more? [1] Yes [2] No:");
//scanf("%d", &choice);
//getchar(); // <== remove newline
total = price*quantity;
break;
//if (choice == 1) {
// menu();
// break;
//}
//else if (choice == 2) {
// grandtotal = grandtotal + total;
// printf("\n Total Price is: %0.2f", grandtotal);
// break;
//}
case 'F':
printf("You selected French Fries!\n");
printf("Enter quantity:");
scanf("%d", &quantity);
price = 47.75;
//printf("\n Do you want to order more? [1] Yes [2] No:");
//scanf("%d", &choice);
total = price*quantity;
break;
//if (choice == 1) {
// menu();
// break;
//}
//else if (choice == 2) {
// grandtotal = grandtotal + total;
// printf("\n Total Price is: %0.2f", grandtotal);
// break;
//}
case 'P':
printf("You selected French Pizza!\n");
printf("Enter quantity:");
scanf("%d", &quantity);
price = 105.00;
//printf("\n Do you want to order more? [1] Yes [2] No:");
//scanf("%d", &choice);
total = price*quantity;
break;
//if (choice == 1) {
// menu();
// break;
//}
//else if (choice == 2) {
// grandtotal = grandtotal + total;
// printf("\n Total Price is: %0.2f", grandtotal);
// break;
//}
case 'S':
printf("You selected Sandwiches\n");
printf("Enter quantity:");
scanf("%d", &quantity);
price = 75.50;
//printf("\n Do you want to order more? [1] Yes [2] No:");
//scanf("%d", &choice);
total = price*quantity;
break;
//if (choice == 1) {
// main();
// break;
//}
//else if (choice == 2) {
// grandtotal = grandtotal + total;
// printf("\n Total Price is: %0.2f", grandtotal);
// break;
//}
default:
printf("INVALID FOOD!");
break;
}
}
3
solved C Program are closing automatically