#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define MAX_MENU 50
#define MAX_USERS 100
// Structure Definitions
typedef struct {
char name[50];
char ingredients[200];
float price;
} MenuItem;
typedef struct {
char username[50];
char password[50];
char address[200];
} User;
// Global Variables
MenuItem riceMenu[MAX_MENU], noodleMenu[MAX_MENU], drinkMenu[MAX_MENU], dessertMenu[MAX_MENU], snackMenu[MAX_MENU];
int riceCount = 0, noodleCount = 0, drinkCount = 0, dessertCount = 0, snackCount = 0;
User users[MAX_USERS];
int userCount = 0;
int loggedInUser = -1;
// Function Declarations
void initializeMenus();
void showMenu
(MenuItem menu
[], int
count, const char
*category
);void customizeOrder(MenuItem *item);
void orderFood
(MenuItem menu
[], int
count);void login();
void signup();
void checkout(float total);
void randomSuggestion();
// Main Function
int main() {
int choice;
initializeMenus();
printf("\n=== ระบบสั่งอาหาร ===\n");
while (1) {
if (loggedInUser == -1) {
printf("กรุณาเข้าสู่ระบบก่อนใช้งาน\n"); printf("1. ล็อกอิน\n2. สมัครสมาชิก\n3. ออกจากโปรแกรม\n"); scanf("%d", &choice);
if (choice == 1) {
login();
} else if (choice == 2) {
signup();
} else if (choice == 3) {
printf("ขอบคุณที่ใช้บริการ\n"); break;
} else {
printf("ตัวเลือกไม่ถูกต้อง\n"); }
} else {
printf("\n--- เมนูหลัก ---\n"); printf("1. ดูเมนูข้าว\n2. ดูเมนูเส้น\n3. ดูเมนูน้ำดื่ม\n4. ดูเมนูของหวาน\n5. ดูเมนูของทานเล่น\n6. สุ่มอาหาร\n7. ออกจากระบบ\n"); scanf("%d", &choice);
if (choice >= 1 && choice <= 5) {
MenuItem *menu;
const char *category;
switch (choice) {
case 1:
menu = riceMenu;
category = "ข้าว";
break;
case 2:
menu = noodleMenu;
category = "เส้น";
break;
case 3:
menu = drinkMenu;
category = "น้ำดื่ม";
break;
case 4:
menu = dessertMenu;
category = "ของหวาน";
break;
case 5:
menu = snackMenu;
category = "ของทานเล่น";
break;
}
showMenu
(menu
, count, category
);
} else if (choice == 6) {
randomSuggestion();
} else if (choice == 7) {
loggedInUser = -1;
} else {
printf("ตัวเลือกไม่ถูกต้อง\n"); }
}
}
return 0;
}
// Function Implementations
void initializeMenus() {
strcpy(riceMenu[0].name, "ข้าวผัดหมู");
strcpy(riceMenu[0].ingredients, "ข้าว, หมู, ไข่, หอมใหญ่, ซอสปรุงรส");
riceMenu[0].price = 50;
riceCount++;
strcpy(noodleMenu[0].name, "ก๋วยเตี๋ยวเรือ");
strcpy(noodleMenu[0].ingredients, "เส้นเล็ก, เนื้อหมู, ต้นหอม, ถั่วงอก, น้ำซุป");
noodleMenu[0].price = 40;
noodleCount++;
strcpy(drinkMenu[0].name, "ชาไทย");
strcpy(drinkMenu[0].ingredients, "ชา, นม, น้ำแข็ง");
drinkMenu[0].price = 25;
drinkCount++;
strcpy(dessertMenu[0].name, "บัวลอย");
strcpy(dessertMenu[0].ingredients, "แป้งข้าวเหนียว, น้ำกะทิ, น้ำตาล");
dessertMenu[0].price = 30;
dessertCount++;
strcpy(snackMenu[0].name, "ปอเปี๊ยะทอด");
strcpy(snackMenu[0].ingredients, "แป้งปอเปี๊ยะ, ผัก, วุ้นเส้น");
snackMenu[0].price = 35;
snackCount++;
}
void showMenu
(MenuItem menu
[], int
count, const char
*category
) { printf("\n--- เมนู%s ---\n", category
); for (int i
= 0; i
< count; i
++) { printf("%d. %s (%.2f บาท)\nส่วนประกอบ: %s\n", i
+ 1, menu
[i
].name
, menu
[i
].price
, menu
[i
].ingredients
); }
}
void customizeOrder(MenuItem *item) {
int choice;
printf("\nคุณต้องการเพิ่มหรือลดส่วนประกอบของ %s หรือไม่?\n", item
->name); printf("1. เพิ่มส่วนประกอบ\n2. ลดส่วนประกอบ\n3. ไม่ปรับแต่ง\nเลือกตัวเลือก: "); scanf("%d", &choice);
if (choice == 1) {
char extra[50];
printf("ป้อนส่วนประกอบที่ต้องการเพิ่ม: "); scanf("%s", extra);
strcat(item->ingredients, ", ");
strcat(item->ingredients, extra);
item->price += 5;
printf("เพิ่ม %s สำเร็จ ราคาใหม่: %.2f บาท\n", extra
, item
->price); } else if (choice == 2) {
char remove[50];
printf("ป้อนส่วนประกอบที่ต้องการลด: "); scanf("%s", remove);
item->price -= 5;
printf("ลด %s สำเร็จ ราคาใหม่: %.2f บาท\n", remove
, item
->price); }
}
void orderFood
(MenuItem menu
[], int
count) { int menuChoice;
float total = 0;
printf("\nเลือกเมนูที่ต้องการ (0 เพื่อเสร็จสิ้น): ");
while (1) {
scanf("%d", &menuChoice);
if (menuChoice == 0) {
break;
}
if (menuChoice
> 0 && menuChoice
<= count) { MenuItem *item = &menu[menuChoice - 1];
customizeOrder(item);
total += item->price;
} else {
printf("ตัวเลือกไม่ถูกต้อง\n"); }
}
checkout(total);
}
void login() {
char username[50], password[50];
printf("\n--- ล็อกอิน ---\n"); scanf("%s", username);
scanf("%s", password);
for (int i = 0; i < userCount; i++) {
if (strcmp(users
[i
].username
, username
) == 0 && strcmp(users
[i
].password
, password
) == 0) { loggedInUser = i;
printf("เข้าสู่ระบบสำเร็จ\n"); return;
}
}
printf("ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง\n"); }
void signup() {
char username[50], password[50], address[200];
printf("\n--- สมัครสมาชิก ---\n"); scanf("%s", username);
scanf("%s", password);
scanf("%s", address);
strcpy(users[userCount].username, username);
strcpy(users[userCount].password, password);
strcpy(users[userCount].address, address);
userCount++;
printf("สมัครสมาชิกสำเร็จ\n"); }
void checkout(float total) {
printf("\nยอดรวมทั้งหมด: %.2f บาท\n", total
); printf("ส่งไปที่: %s\n", users
[loggedInUser
].address
); printf("ขอบคุณที่ใช้บริการ\n"); }
void randomSuggestion() {
int category
= rand() % 5; MenuItem *menu;
switch (category) {
case 0:
menu = riceMenu;
break;
case 1:
menu = noodleMenu;
break;
case 2:
menu = drinkMenu;
break;
case 3:
menu = dessertMenu;
break;
case 4:
menu = snackMenu;
break;
}
printf("\nเมนูแนะนำ: %s (%.2f บาท)\nส่วนประกอบ: %s\n", menu
[randomIndex
].name
, menu
[randomIndex
].price
, menu
[randomIndex
].ingredients
);
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8dGltZS5oPgoKI2RlZmluZSBNQVhfTUVOVSA1MAojZGVmaW5lIE1BWF9VU0VSUyAxMDAKCi8vIFN0cnVjdHVyZSBEZWZpbml0aW9ucwp0eXBlZGVmIHN0cnVjdCB7CiAgICBjaGFyIG5hbWVbNTBdOwogICAgY2hhciBpbmdyZWRpZW50c1syMDBdOwogICAgZmxvYXQgcHJpY2U7Cn0gTWVudUl0ZW07Cgp0eXBlZGVmIHN0cnVjdCB7CiAgICBjaGFyIHVzZXJuYW1lWzUwXTsKICAgIGNoYXIgcGFzc3dvcmRbNTBdOwogICAgY2hhciBhZGRyZXNzWzIwMF07Cn0gVXNlcjsKCi8vIEdsb2JhbCBWYXJpYWJsZXMKTWVudUl0ZW0gcmljZU1lbnVbTUFYX01FTlVdLCBub29kbGVNZW51W01BWF9NRU5VXSwgZHJpbmtNZW51W01BWF9NRU5VXSwgZGVzc2VydE1lbnVbTUFYX01FTlVdLCBzbmFja01lbnVbTUFYX01FTlVdOwppbnQgcmljZUNvdW50ID0gMCwgbm9vZGxlQ291bnQgPSAwLCBkcmlua0NvdW50ID0gMCwgZGVzc2VydENvdW50ID0gMCwgc25hY2tDb3VudCA9IDA7ClVzZXIgdXNlcnNbTUFYX1VTRVJTXTsKaW50IHVzZXJDb3VudCA9IDA7CmludCBsb2dnZWRJblVzZXIgPSAtMTsKCi8vIEZ1bmN0aW9uIERlY2xhcmF0aW9ucwp2b2lkIGluaXRpYWxpemVNZW51cygpOwp2b2lkIHNob3dNZW51KE1lbnVJdGVtIG1lbnVbXSwgaW50IGNvdW50LCBjb25zdCBjaGFyICpjYXRlZ29yeSk7CnZvaWQgY3VzdG9taXplT3JkZXIoTWVudUl0ZW0gKml0ZW0pOwp2b2lkIG9yZGVyRm9vZChNZW51SXRlbSBtZW51W10sIGludCBjb3VudCk7CnZvaWQgbG9naW4oKTsKdm9pZCBzaWdudXAoKTsKdm9pZCBjaGVja291dChmbG9hdCB0b3RhbCk7CnZvaWQgcmFuZG9tU3VnZ2VzdGlvbigpOwoKLy8gTWFpbiBGdW5jdGlvbgppbnQgbWFpbigpIHsKICAgIGludCBjaG9pY2U7CiAgICBpbml0aWFsaXplTWVudXMoKTsKCiAgICBwcmludGYoIlxuPT09IOC4o+C4sOC4muC4muC4quC4seC5iOC4h+C4reC4suC4q+C4suC4oyA9PT1cbiIpOwoKICAgIHdoaWxlICgxKSB7CiAgICAgICAgaWYgKGxvZ2dlZEluVXNlciA9PSAtMSkgewogICAgICAgICAgICBwcmludGYoIuC4geC4o+C4uOC4k+C4suC5gOC4guC5ieC4suC4quC4ueC5iOC4o+C4sOC4muC4muC4geC5iOC4reC4meC5g+C4iuC5ieC4h+C4suC4mVxuIik7CiAgICAgICAgICAgIHByaW50ZigiMS4g4Lil4LmH4Lit4LiB4Lit4Li04LiZXG4yLiDguKrguKHguLHguITguKPguKrguKHguLLguIrguLTguIFcbjMuIOC4reC4reC4geC4iOC4suC4geC5guC4m+C4o+C5geC4geC4o+C4oVxuIik7CiAgICAgICAgICAgIHByaW50Zigi4LmA4Lil4Li34Lit4LiB4LiV4Lix4Lin4LmA4Lil4Li34Lit4LiBOiAiKTsKICAgICAgICAgICAgc2NhbmYoIiVkIiwgJmNob2ljZSk7CgogICAgICAgICAgICBpZiAoY2hvaWNlID09IDEpIHsKICAgICAgICAgICAgICAgIGxvZ2luKCk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoY2hvaWNlID09IDIpIHsKICAgICAgICAgICAgICAgIHNpZ251cCgpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGNob2ljZSA9PSAzKSB7CiAgICAgICAgICAgICAgICBwcmludGYoIuC4guC4reC4muC4hOC4uOC4k+C4l+C4teC5iOC5g+C4iuC5ieC4muC4o+C4tOC4geC4suC4o1xuIik7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHByaW50Zigi4LiV4Lix4Lin4LmA4Lil4Li34Lit4LiB4LmE4Lih4LmI4LiW4Li54LiB4LiV4LmJ4Lit4LiHXG4iKTsKICAgICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHByaW50ZigiXG4tLS0g4LmA4Lih4LiZ4Li54Lir4Lil4Lix4LiBIC0tLVxuIik7CiAgICAgICAgICAgIHByaW50ZigiMS4g4LiU4Li54LmA4Lih4LiZ4Li54LiC4LmJ4Liy4LinXG4yLiDguJTguLnguYDguKHguJnguLnguYDguKrguYnguJlcbjMuIOC4lOC4ueC5gOC4oeC4meC4ueC4meC5ieC4s+C4lOC4t+C5iOC4oVxuNC4g4LiU4Li54LmA4Lih4LiZ4Li54LiC4Lit4LiH4Lir4Lin4Liy4LiZXG41LiDguJTguLnguYDguKHguJnguLnguILguK3guIfguJfguLLguJnguYDguKXguYjguJlcbjYuIOC4quC4uOC5iOC4oeC4reC4suC4q+C4suC4o1xuNy4g4Lit4Lit4LiB4LiI4Liy4LiB4Lij4Liw4Lia4LiaXG4iKTsKICAgICAgICAgICAgcHJpbnRmKCLguYDguKXguLfguK3guIHguJXguLHguKfguYDguKXguLfguK3guIE6ICIpOwogICAgICAgICAgICBzY2FuZigiJWQiLCAmY2hvaWNlKTsKCiAgICAgICAgICAgIGlmIChjaG9pY2UgPj0gMSAmJiBjaG9pY2UgPD0gNSkgewogICAgICAgICAgICAgICAgTWVudUl0ZW0gKm1lbnU7CiAgICAgICAgICAgICAgICBpbnQgY291bnQ7CiAgICAgICAgICAgICAgICBjb25zdCBjaGFyICpjYXRlZ29yeTsKCiAgICAgICAgICAgICAgICBzd2l0Y2ggKGNob2ljZSkgewogICAgICAgICAgICAgICAgICAgIGNhc2UgMToKICAgICAgICAgICAgICAgICAgICAgICAgbWVudSA9IHJpY2VNZW51OwogICAgICAgICAgICAgICAgICAgICAgICBjb3VudCA9IHJpY2VDb3VudDsKICAgICAgICAgICAgICAgICAgICAgICAgY2F0ZWdvcnkgPSAi4LiC4LmJ4Liy4LinIjsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgICAgICAgICBtZW51ID0gbm9vZGxlTWVudTsKICAgICAgICAgICAgICAgICAgICAgICAgY291bnQgPSBub29kbGVDb3VudDsKICAgICAgICAgICAgICAgICAgICAgICAgY2F0ZWdvcnkgPSAi4LmA4Liq4LmJ4LiZIjsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgICAgICAgICBtZW51ID0gZHJpbmtNZW51OwogICAgICAgICAgICAgICAgICAgICAgICBjb3VudCA9IGRyaW5rQ291bnQ7CiAgICAgICAgICAgICAgICAgICAgICAgIGNhdGVnb3J5ID0gIuC4meC5ieC4s+C4lOC4t+C5iOC4oSI7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgICAgICAgICAgbWVudSA9IGRlc3NlcnRNZW51OwogICAgICAgICAgICAgICAgICAgICAgICBjb3VudCA9IGRlc3NlcnRDb3VudDsKICAgICAgICAgICAgICAgICAgICAgICAgY2F0ZWdvcnkgPSAi4LiC4Lit4LiH4Lir4Lin4Liy4LiZIjsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgY2FzZSA1OgogICAgICAgICAgICAgICAgICAgICAgICBtZW51ID0gc25hY2tNZW51OwogICAgICAgICAgICAgICAgICAgICAgICBjb3VudCA9IHNuYWNrQ291bnQ7CiAgICAgICAgICAgICAgICAgICAgICAgIGNhdGVnb3J5ID0gIuC4guC4reC4h+C4l+C4suC4meC5gOC4peC5iOC4mSI7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIHNob3dNZW51KG1lbnUsIGNvdW50LCBjYXRlZ29yeSk7CiAgICAgICAgICAgICAgICBvcmRlckZvb2QobWVudSwgY291bnQpOwoKICAgICAgICAgICAgfSBlbHNlIGlmIChjaG9pY2UgPT0gNikgewogICAgICAgICAgICAgICAgcmFuZG9tU3VnZ2VzdGlvbigpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGNob2ljZSA9PSA3KSB7CiAgICAgICAgICAgICAgICBsb2dnZWRJblVzZXIgPSAtMTsKICAgICAgICAgICAgICAgIHByaW50Zigi4Lit4Lit4LiB4LiI4Liy4LiB4Lij4Liw4Lia4Lia4Liq4Liz4LmA4Lij4LmH4LiIXG4iKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHByaW50Zigi4LiV4Lix4Lin4LmA4Lil4Li34Lit4LiB4LmE4Lih4LmI4LiW4Li54LiB4LiV4LmJ4Lit4LiHXG4iKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gMDsKfQoKLy8gRnVuY3Rpb24gSW1wbGVtZW50YXRpb25zCnZvaWQgaW5pdGlhbGl6ZU1lbnVzKCkgewogICAgc3RyY3B5KHJpY2VNZW51WzBdLm5hbWUsICLguILguYnguLLguKfguJzguLHguJTguKvguKHguLkiKTsKICAgIHN0cmNweShyaWNlTWVudVswXS5pbmdyZWRpZW50cywgIuC4guC5ieC4suC4pywg4Lir4Lih4Li5LCDguYTguILguYgsIOC4q+C4reC4oeC5g+C4q+C4jeC5iCwg4LiL4Lit4Liq4Lib4Lij4Li44LiH4Lij4LiqIik7CiAgICByaWNlTWVudVswXS5wcmljZSA9IDUwOwogICAgcmljZUNvdW50Kys7CgogICAgc3RyY3B5KG5vb2RsZU1lbnVbMF0ubmFtZSwgIuC4geC5i+C4p+C4ouC5gOC4leC4teC5i+C4ouC4p+C5gOC4o+C4t+C4rSIpOwogICAgc3RyY3B5KG5vb2RsZU1lbnVbMF0uaW5ncmVkaWVudHMsICLguYDguKrguYnguJnguYDguKXguYfguIEsIOC5gOC4meC4t+C5ieC4reC4q+C4oeC4uSwg4LiV4LmJ4LiZ4Lir4Lit4LihLCDguJbguLHguYjguKfguIfguK3guIEsIOC4meC5ieC4s+C4i+C4uOC4myIpOwogICAgbm9vZGxlTWVudVswXS5wcmljZSA9IDQwOwogICAgbm9vZGxlQ291bnQrKzsKCiAgICBzdHJjcHkoZHJpbmtNZW51WzBdLm5hbWUsICLguIrguLLguYTguJfguKIiKTsKICAgIHN0cmNweShkcmlua01lbnVbMF0uaW5ncmVkaWVudHMsICLguIrguLIsIOC4meC4oSwg4LiZ4LmJ4Liz4LmB4LiC4LmH4LiHIik7CiAgICBkcmlua01lbnVbMF0ucHJpY2UgPSAyNTsKICAgIGRyaW5rQ291bnQrKzsKCiAgICBzdHJjcHkoZGVzc2VydE1lbnVbMF0ubmFtZSwgIuC4muC4seC4p+C4peC4reC4oiIpOwogICAgc3RyY3B5KGRlc3NlcnRNZW51WzBdLmluZ3JlZGllbnRzLCAi4LmB4Lib4LmJ4LiH4LiC4LmJ4Liy4Lin4LmA4Lir4LiZ4Li14Lii4LinLCDguJnguYnguLPguIHguLDguJfguLQsIOC4meC5ieC4s+C4leC4suC4pSIpOwogICAgZGVzc2VydE1lbnVbMF0ucHJpY2UgPSAzMDsKICAgIGRlc3NlcnRDb3VudCsrOwoKICAgIHN0cmNweShzbmFja01lbnVbMF0ubmFtZSwgIuC4m+C4reC5gOC4m+C4teC5iuC4ouC4sOC4l+C4reC4lCIpOwogICAgc3RyY3B5KHNuYWNrTWVudVswXS5pbmdyZWRpZW50cywgIuC5geC4m+C5ieC4h+C4m+C4reC5gOC4m+C4teC5iuC4ouC4sCwg4Lic4Lix4LiBLCDguKfguLjguYnguJnguYDguKrguYnguJkiKTsKICAgIHNuYWNrTWVudVswXS5wcmljZSA9IDM1OwogICAgc25hY2tDb3VudCsrOwp9Cgp2b2lkIHNob3dNZW51KE1lbnVJdGVtIG1lbnVbXSwgaW50IGNvdW50LCBjb25zdCBjaGFyICpjYXRlZ29yeSkgewogICAgcHJpbnRmKCJcbi0tLSDguYDguKHguJnguLklcyAtLS1cbiIsIGNhdGVnb3J5KTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgY291bnQ7IGkrKykgewogICAgICAgIHByaW50ZigiJWQuICVzICglLjJmIOC4muC4suC4lylcbuC4quC5iOC4p+C4meC4m+C4o+C4sOC4geC4reC4mjogJXNcbiIsIGkgKyAxLCBtZW51W2ldLm5hbWUsIG1lbnVbaV0ucHJpY2UsIG1lbnVbaV0uaW5ncmVkaWVudHMpOwogICAgfQp9Cgp2b2lkIGN1c3RvbWl6ZU9yZGVyKE1lbnVJdGVtICppdGVtKSB7CiAgICBpbnQgY2hvaWNlOwogICAgcHJpbnRmKCJcbuC4hOC4uOC4k+C4leC5ieC4reC4h+C4geC4suC4o+C5gOC4nuC4tOC5iOC4oeC4q+C4o+C4t+C4reC4peC4lOC4quC5iOC4p+C4meC4m+C4o+C4sOC4geC4reC4muC4guC4reC4hyAlcyDguKvguKPguLfguK3guYTguKHguYg/XG4iLCBpdGVtLT5uYW1lKTsKICAgIHByaW50ZigiMS4g4LmA4Lie4Li04LmI4Lih4Liq4LmI4Lin4LiZ4Lib4Lij4Liw4LiB4Lit4LiaXG4yLiDguKXguJTguKrguYjguKfguJnguJvguKPguLDguIHguK3guJpcbjMuIOC5hOC4oeC5iOC4m+C4o+C4seC4muC5geC4leC5iOC4h1xu4LmA4Lil4Li34Lit4LiB4LiV4Lix4Lin4LmA4Lil4Li34Lit4LiBOiAiKTsKICAgIHNjYW5mKCIlZCIsICZjaG9pY2UpOwoKICAgIGlmIChjaG9pY2UgPT0gMSkgewogICAgICAgIGNoYXIgZXh0cmFbNTBdOwogICAgICAgIHByaW50Zigi4Lib4LmJ4Lit4LiZ4Liq4LmI4Lin4LiZ4Lib4Lij4Liw4LiB4Lit4Lia4LiX4Li14LmI4LiV4LmJ4Lit4LiH4LiB4Liy4Lij4LmA4Lie4Li04LmI4LihOiAiKTsKICAgICAgICBzY2FuZigiJXMiLCBleHRyYSk7CiAgICAgICAgc3RyY2F0KGl0ZW0tPmluZ3JlZGllbnRzLCAiLCAiKTsKICAgICAgICBzdHJjYXQoaXRlbS0+aW5ncmVkaWVudHMsIGV4dHJhKTsKICAgICAgICBpdGVtLT5wcmljZSArPSA1OwogICAgICAgIHByaW50Zigi4LmA4Lie4Li04LmI4LihICVzIOC4quC4s+C5gOC4o+C5h+C4iCDguKPguLLguITguLLguYPguKvguKHguYg6ICUuMmYg4Lia4Liy4LiXXG4iLCBleHRyYSwgaXRlbS0+cHJpY2UpOwogICAgfSBlbHNlIGlmIChjaG9pY2UgPT0gMikgewogICAgICAgIGNoYXIgcmVtb3ZlWzUwXTsKICAgICAgICBwcmludGYoIuC4m+C5ieC4reC4meC4quC5iOC4p+C4meC4m+C4o+C4sOC4geC4reC4muC4l+C4teC5iOC4leC5ieC4reC4h+C4geC4suC4o+C4peC4lDogIik7CiAgICAgICAgc2NhbmYoIiVzIiwgcmVtb3ZlKTsKICAgICAgICBpdGVtLT5wcmljZSAtPSA1OwogICAgICAgIHByaW50Zigi4Lil4LiUICVzIOC4quC4s+C5gOC4o+C5h+C4iCDguKPguLLguITguLLguYPguKvguKHguYg6ICUuMmYg4Lia4Liy4LiXXG4iLCByZW1vdmUsIGl0ZW0tPnByaWNlKTsKICAgIH0KfQoKdm9pZCBvcmRlckZvb2QoTWVudUl0ZW0gbWVudVtdLCBpbnQgY291bnQpIHsKICAgIGludCBtZW51Q2hvaWNlOwogICAgZmxvYXQgdG90YWwgPSAwOwogICAgcHJpbnRmKCJcbuC5gOC4peC4t+C4reC4geC5gOC4oeC4meC4ueC4l+C4teC5iOC4leC5ieC4reC4h+C4geC4suC4oyAoMCDguYDguJ7guLfguYjguK3guYDguKrguKPguYfguIjguKrguLTguYnguJkpOiAiKTsKCiAgICB3aGlsZSAoMSkgewogICAgICAgIHNjYW5mKCIlZCIsICZtZW51Q2hvaWNlKTsKCiAgICAgICAgaWYgKG1lbnVDaG9pY2UgPT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICB9CgogICAgICAgIGlmIChtZW51Q2hvaWNlID4gMCAmJiBtZW51Q2hvaWNlIDw9IGNvdW50KSB7CiAgICAgICAgICAgIE1lbnVJdGVtICppdGVtID0gJm1lbnVbbWVudUNob2ljZSAtIDFdOwogICAgICAgICAgICBjdXN0b21pemVPcmRlcihpdGVtKTsKICAgICAgICAgICAgdG90YWwgKz0gaXRlbS0+cHJpY2U7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcHJpbnRmKCLguJXguLHguKfguYDguKXguLfguK3guIHguYTguKHguYjguJbguLnguIHguJXguYnguK3guIdcbiIpOwogICAgICAgIH0KICAgIH0KCiAgICBjaGVja291dCh0b3RhbCk7Cn0KCnZvaWQgbG9naW4oKSB7CiAgICBjaGFyIHVzZXJuYW1lWzUwXSwgcGFzc3dvcmRbNTBdOwogICAgcHJpbnRmKCJcbi0tLSDguKXguYfguK3guIHguK3guLTguJkgLS0tXG4iKTsKICAgIHByaW50Zigi4LiK4Li34LmI4Lit4Lic4Li54LmJ4LmD4LiK4LmJOiAiKTsKICAgIHNjYW5mKCIlcyIsIHVzZXJuYW1lKTsKICAgIHByaW50Zigi4Lij4Lir4Lix4Liq4Lic4LmI4Liy4LiZOiAiKTsKICAgIHNjYW5mKCIlcyIsIHBhc3N3b3JkKTsKCiAgICBmb3IgKGludCBpID0gMDsgaSA8IHVzZXJDb3VudDsgaSsrKSB7CiAgICAgICAgaWYgKHN0cmNtcCh1c2Vyc1tpXS51c2VybmFtZSwgdXNlcm5hbWUpID09IDAgJiYgc3RyY21wKHVzZXJzW2ldLnBhc3N3b3JkLCBwYXNzd29yZCkgPT0gMCkgewogICAgICAgICAgICBsb2dnZWRJblVzZXIgPSBpOwogICAgICAgICAgICBwcmludGYoIuC5gOC4guC5ieC4suC4quC4ueC5iOC4o+C4sOC4muC4muC4quC4s+C5gOC4o+C5h+C4iFxuIik7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICB9CgogICAgcHJpbnRmKCLguIrguLfguYjguK3guJzguLnguYnguYPguIrguYnguKvguKPguLfguK3guKPguKvguLHguKrguJzguYjguLLguJnguYTguKHguYjguJbguLnguIHguJXguYnguK3guIdcbiIpOwp9Cgp2b2lkIHNpZ251cCgpIHsKICAgIGNoYXIgdXNlcm5hbWVbNTBdLCBwYXNzd29yZFs1MF0sIGFkZHJlc3NbMjAwXTsKICAgIHByaW50ZigiXG4tLS0g4Liq4Lih4Lix4LiE4Lij4Liq4Lih4Liy4LiK4Li04LiBIC0tLVxuIik7CiAgICBwcmludGYoIuC4iuC4t+C5iOC4reC4nOC4ueC5ieC5g+C4iuC5iTogIik7CiAgICBzY2FuZigiJXMiLCB1c2VybmFtZSk7CiAgICBwcmludGYoIuC4o+C4q+C4seC4quC4nOC5iOC4suC4mTogIik7CiAgICBzY2FuZigiJXMiLCBwYXNzd29yZCk7CiAgICBwcmludGYoIuC4l+C4teC5iOC4reC4ouC4ueC5iDogIik7CiAgICBzY2FuZigiJXMiLCBhZGRyZXNzKTsKCiAgICBzdHJjcHkodXNlcnNbdXNlckNvdW50XS51c2VybmFtZSwgdXNlcm5hbWUpOwogICAgc3RyY3B5KHVzZXJzW3VzZXJDb3VudF0ucGFzc3dvcmQsIHBhc3N3b3JkKTsKICAgIHN0cmNweSh1c2Vyc1t1c2VyQ291bnRdLmFkZHJlc3MsIGFkZHJlc3MpOwogICAgdXNlckNvdW50Kys7CgogICAgcHJpbnRmKCLguKrguKHguLHguITguKPguKrguKHguLLguIrguLTguIHguKrguLPguYDguKPguYfguIhcbiIpOwp9Cgp2b2lkIGNoZWNrb3V0KGZsb2F0IHRvdGFsKSB7CiAgICBwcmludGYoIlxu4Lii4Lit4LiU4Lij4Lin4Lih4LiX4Lix4LmJ4LiH4Lir4Lih4LiUOiAlLjJmIOC4muC4suC4l1xuIiwgdG90YWwpOwogICAgcHJpbnRmKCLguKrguYjguIfguYTguJvguJfguLXguYg6ICVzXG4iLCB1c2Vyc1tsb2dnZWRJblVzZXJdLmFkZHJlc3MpOwogICAgcHJpbnRmKCLguILguK3guJrguITguLjguJPguJfguLXguYjguYPguIrguYnguJrguKPguLTguIHguLLguKNcbiIpOwp9Cgp2b2lkIHJhbmRvbVN1Z2dlc3Rpb24oKSB7CiAgICBzcmFuZCh0aW1lKE5VTEwpKTsKICAgIGludCBjYXRlZ29yeSA9IHJhbmQoKSAlIDU7CiAgICBNZW51SXRlbSAqbWVudTsKICAgIGludCBjb3VudDsKCiAgICBzd2l0Y2ggKGNhdGVnb3J5KSB7CiAgICAgICAgY2FzZSAwOgogICAgICAgICAgICBtZW51ID0gcmljZU1lbnU7CiAgICAgICAgICAgIGNvdW50ID0gcmljZUNvdW50OwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIDE6CiAgICAgICAgICAgIG1lbnUgPSBub29kbGVNZW51OwogICAgICAgICAgICBjb3VudCA9IG5vb2RsZUNvdW50OwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgIG1lbnUgPSBkcmlua01lbnU7CiAgICAgICAgICAgIGNvdW50ID0gZHJpbmtDb3VudDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSAzOgogICAgICAgICAgICBtZW51ID0gZGVzc2VydE1lbnU7CiAgICAgICAgICAgIGNvdW50ID0gZGVzc2VydENvdW50OwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIDQ6CiAgICAgICAgICAgIG1lbnUgPSBzbmFja01lbnU7CiAgICAgICAgICAgIGNvdW50ID0gc25hY2tDb3VudDsKICAgICAgICAgICAgYnJlYWs7CiAgICB9CgogICAgaW50IHJhbmRvbUluZGV4ID0gcmFuZCgpICUgY291bnQ7CiAgICBwcmludGYoIlxu4LmA4Lih4LiZ4Li54LmB4LiZ4Liw4LiZ4LizOiAlcyAoJS4yZiDguJrguLLguJcpXG7guKrguYjguKfguJnguJvguKPguLDguIHguK3guJo6ICVzXG4iLCBtZW51W3JhbmRvbUluZGV4XS5uYW1lLCBtZW51W3JhbmRvbUluZGV4XS5wcmljZSwgbWVudVtyYW5kb21JbmRleF0uaW5ncmVkaWVudHMpOwo=
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define MAX_MENU 50
#define MAX_USERS 100
// Structure Definitions
typedef struct {
char name[50];
char ingredients[200];
float price;
} MenuItem;
typedef struct {
char username[50];
char password[50];
char address[200];
} User;
// Global Variables
MenuItem riceMenu[MAX_MENU], noodleMenu[MAX_MENU], drinkMenu[MAX_MENU], dessertMenu[MAX_MENU], snackMenu[MAX_MENU];
int riceCount = 0, noodleCount = 0, drinkCount = 0, dessertCount = 0, snackCount = 0;
User users[MAX_USERS];
int userCount = 0;
int loggedInUser = -1;
// Function Declarations
void initializeMenus();
void showMenu(MenuItem menu[], int count, const char *category);
void customizeOrder(MenuItem *item);
void orderFood(MenuItem menu[], int count);
void login();
void signup();
void checkout(float total);
void randomSuggestion();
// Main Function
int main() {
int choice;
initializeMenus();
printf("\n=== ระบบสั่งอาหาร ===\n");
while (1) {
if (loggedInUser == -1) {
printf("กรุณาเข้าสู่ระบบก่อนใช้งาน\n");
printf("1. ล็อกอิน\n2. สมัครสมาชิก\n3. ออกจากโปรแกรม\n");
printf("เลือกตัวเลือก: ");
scanf("%d", &choice);
if (choice == 1) {
login();
} else if (choice == 2) {
signup();
} else if (choice == 3) {
printf("ขอบคุณที่ใช้บริการ\n");
break;
} else {
printf("ตัวเลือกไม่ถูกต้อง\n");
}
} else {
printf("\n--- เมนูหลัก ---\n");
printf("1. ดูเมนูข้าว\n2. ดูเมนูเส้น\n3. ดูเมนูน้ำดื่ม\n4. ดูเมนูของหวาน\n5. ดูเมนูของทานเล่น\n6. สุ่มอาหาร\n7. ออกจากระบบ\n");
printf("เลือกตัวเลือก: ");
scanf("%d", &choice);
if (choice >= 1 && choice <= 5) {
MenuItem *menu;
int count;
const char *category;
switch (choice) {
case 1:
menu = riceMenu;
count = riceCount;
category = "ข้าว";
break;
case 2:
menu = noodleMenu;
count = noodleCount;
category = "เส้น";
break;
case 3:
menu = drinkMenu;
count = drinkCount;
category = "น้ำดื่ม";
break;
case 4:
menu = dessertMenu;
count = dessertCount;
category = "ของหวาน";
break;
case 5:
menu = snackMenu;
count = snackCount;
category = "ของทานเล่น";
break;
}
showMenu(menu, count, category);
orderFood(menu, count);
} else if (choice == 6) {
randomSuggestion();
} else if (choice == 7) {
loggedInUser = -1;
printf("ออกจากระบบสำเร็จ\n");
} else {
printf("ตัวเลือกไม่ถูกต้อง\n");
}
}
}
return 0;
}
// Function Implementations
void initializeMenus() {
strcpy(riceMenu[0].name, "ข้าวผัดหมู");
strcpy(riceMenu[0].ingredients, "ข้าว, หมู, ไข่, หอมใหญ่, ซอสปรุงรส");
riceMenu[0].price = 50;
riceCount++;
strcpy(noodleMenu[0].name, "ก๋วยเตี๋ยวเรือ");
strcpy(noodleMenu[0].ingredients, "เส้นเล็ก, เนื้อหมู, ต้นหอม, ถั่วงอก, น้ำซุป");
noodleMenu[0].price = 40;
noodleCount++;
strcpy(drinkMenu[0].name, "ชาไทย");
strcpy(drinkMenu[0].ingredients, "ชา, นม, น้ำแข็ง");
drinkMenu[0].price = 25;
drinkCount++;
strcpy(dessertMenu[0].name, "บัวลอย");
strcpy(dessertMenu[0].ingredients, "แป้งข้าวเหนียว, น้ำกะทิ, น้ำตาล");
dessertMenu[0].price = 30;
dessertCount++;
strcpy(snackMenu[0].name, "ปอเปี๊ยะทอด");
strcpy(snackMenu[0].ingredients, "แป้งปอเปี๊ยะ, ผัก, วุ้นเส้น");
snackMenu[0].price = 35;
snackCount++;
}
void showMenu(MenuItem menu[], int count, const char *category) {
printf("\n--- เมนู%s ---\n", category);
for (int i = 0; i < count; i++) {
printf("%d. %s (%.2f บาท)\nส่วนประกอบ: %s\n", i + 1, menu[i].name, menu[i].price, menu[i].ingredients);
}
}
void customizeOrder(MenuItem *item) {
int choice;
printf("\nคุณต้องการเพิ่มหรือลดส่วนประกอบของ %s หรือไม่?\n", item->name);
printf("1. เพิ่มส่วนประกอบ\n2. ลดส่วนประกอบ\n3. ไม่ปรับแต่ง\nเลือกตัวเลือก: ");
scanf("%d", &choice);
if (choice == 1) {
char extra[50];
printf("ป้อนส่วนประกอบที่ต้องการเพิ่ม: ");
scanf("%s", extra);
strcat(item->ingredients, ", ");
strcat(item->ingredients, extra);
item->price += 5;
printf("เพิ่ม %s สำเร็จ ราคาใหม่: %.2f บาท\n", extra, item->price);
} else if (choice == 2) {
char remove[50];
printf("ป้อนส่วนประกอบที่ต้องการลด: ");
scanf("%s", remove);
item->price -= 5;
printf("ลด %s สำเร็จ ราคาใหม่: %.2f บาท\n", remove, item->price);
}
}
void orderFood(MenuItem menu[], int count) {
int menuChoice;
float total = 0;
printf("\nเลือกเมนูที่ต้องการ (0 เพื่อเสร็จสิ้น): ");
while (1) {
scanf("%d", &menuChoice);
if (menuChoice == 0) {
break;
}
if (menuChoice > 0 && menuChoice <= count) {
MenuItem *item = &menu[menuChoice - 1];
customizeOrder(item);
total += item->price;
} else {
printf("ตัวเลือกไม่ถูกต้อง\n");
}
}
checkout(total);
}
void login() {
char username[50], password[50];
printf("\n--- ล็อกอิน ---\n");
printf("ชื่อผู้ใช้: ");
scanf("%s", username);
printf("รหัสผ่าน: ");
scanf("%s", password);
for (int i = 0; i < userCount; i++) {
if (strcmp(users[i].username, username) == 0 && strcmp(users[i].password, password) == 0) {
loggedInUser = i;
printf("เข้าสู่ระบบสำเร็จ\n");
return;
}
}
printf("ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง\n");
}
void signup() {
char username[50], password[50], address[200];
printf("\n--- สมัครสมาชิก ---\n");
printf("ชื่อผู้ใช้: ");
scanf("%s", username);
printf("รหัสผ่าน: ");
scanf("%s", password);
printf("ที่อยู่: ");
scanf("%s", address);
strcpy(users[userCount].username, username);
strcpy(users[userCount].password, password);
strcpy(users[userCount].address, address);
userCount++;
printf("สมัครสมาชิกสำเร็จ\n");
}
void checkout(float total) {
printf("\nยอดรวมทั้งหมด: %.2f บาท\n", total);
printf("ส่งไปที่: %s\n", users[loggedInUser].address);
printf("ขอบคุณที่ใช้บริการ\n");
}
void randomSuggestion() {
srand(time(NULL));
int category = rand() % 5;
MenuItem *menu;
int count;
switch (category) {
case 0:
menu = riceMenu;
count = riceCount;
break;
case 1:
menu = noodleMenu;
count = noodleCount;
break;
case 2:
menu = drinkMenu;
count = drinkCount;
break;
case 3:
menu = dessertMenu;
count = dessertCount;
break;
case 4:
menu = snackMenu;
count = snackCount;
break;
}
int randomIndex = rand() % count;
printf("\nเมนูแนะนำ: %s (%.2f บาท)\nส่วนประกอบ: %s\n", menu[randomIndex].name, menu[randomIndex].price, menu[randomIndex].ingredients);