#include <stdio.h>
#include <stdlib.h>
void clrscr() {
system("cls"); // For Windows, change to "clear" for Linux
}
void divider() {
printf("\n--------------------------------\n");
}
void title(const char *str) {
divider();
printf(" %s", str);
divider();
}
void printPrice(double totalP, int totalI) {
divider();
printf("Total items : %d\n", totalI);
printf("Total price : php%g", totalP);
divider();
}
void invalid() {
divider();
printf(" Invalid choice !");
}
int askChoice() {
int ch;
printf("\nChoice : ");
scanf("%d", &ch);
return ch;
}
void processMenu(const char *menuTitle, const char **menuItems, const double *prices, int menuSize,
double *totalPrice, int *totalItems) {
clrscr();
title(menuTitle);
for (int i = 0; i < menuSize; i++) {
printf(" (%d) %s : php%g\n", i + 1, menuItems[i], prices[i]);
}
printf(" (%d) Back\n", menuSize + 1);
printPrice(*totalPrice, *totalItems);
int choice = askChoice();
if (choice < 1 || choice > menuSize + 1) {
clrscr();
invalid();
} else if (choice == menuSize + 1) {
clrscr();
// Do nothing, let it go back to the main menu
} else {
*totalPrice += prices[choice - 1];
*totalItems += 1;
clrscr();
printf("You've added %s to your order.\n", menuItems[choice - 1]);
// Additional processing can be added here if needed
}
}
int main() {
double totalPrice = 0.0;
int totalItems = 0;
int mainMenuItems = 6;
const char *mainMenu[] = {
"Buy 1 take 1", "Single Order", "Beverages", "Check out", "Reset", "Exit"
};
int quit = 0;
while (!quit) {
clrscr();
title("Thai me UP");
for (int i = 0; i < mainMenuItems; i++) {
printf(" (%d): %s\n", i + 1, mainMenu[i]);
}
printPrice(totalPrice, totalItems);
int choice = askChoice();
switch (choice) {
case 1:
processMenu("Buy 1 Take 1", (const char *[]){"Burger", "Cheese Burger", "Hotdog sandwich"},
(const double[]){40, 50, 50}, 3, &totalPrice, &totalItems);
break;
case 2:
processMenu("Single Order", (const char *[]){"Burger with egg", "Burger with ham", "Cheese burger with egg", "Double patty"},
(const double[]){35, 35, 40, 40}, 4, &totalPrice, &totalItems);
break;
case 3:
processMenu("Beverages", (const char *[]){"Mineral Water", "Coke", "Mountain Dew"},
(const double[]){15, 22, 22}, 3, &totalPrice, &totalItems);
break;
case 4:
clrscr();
title("Check out");
printf("\nYour order will be arrived shortly.\n");
printPrice(totalPrice, totalItems);
break;
case 5:
totalPrice = 0.0;
totalItems = 0;
clrscr();
break;
case 6:
quit = 1;
break;
default:
clrscr();
invalid();
}
}
return 0;
}