Code:
# include <conio.h># include <stdio.h>
# include <stdlib.h>
# include <string.h>
#define PASSWORD 161996
#define TEXTSIZE 80
#define TAX 0.01
#define NUM_BREAKFAST_ITEMS 3
#define NUM_LUNCH_ITEMS 3
#define NUM_DINNER_ITEMS 3
#define NUM_DESSERT_ITEMS 6
#define NUM_BEVERAGE_ITEMS 6
struct MenuData {
char name[TEXTSIZE];
char desc[2][TEXTSIZE];
char prepare[2][TEXTSIZE];
float price;
};
typedef struct MenuData MenuData;
/*Initialization of array elements MenuData*/
const MenuData breakfast[NUM_BREAKFAST_ITEMS] = {
{"Egg Breakfast", "Two eggs with a side of bacon and two slices of toast.", "", "2 Eggs, 2 Toats, 2 Bacons", "", 250.00},
{"Pancake Breakfast", "Three Buttermilk pancakes, butter and syrup.", "", "Three Pancakes, Butter, Syrup", "", 200.00},
{"Meat Variety", "Three eggs, bacon and", "smoked sausages,porridge, three fried dumplings and jam.", "1 Bowl Poridge,", "3 Fried Dumplings, Jam", 350.00}
};
const MenuData lunch[NUM_LUNCH_ITEMS]= {
{"Cheese Burger", " Thick-sliced bacon and two slices of tastee", "cheese served with seared buns and fries.", "Cheese Burger, Fries", "", 450.00,},
{"Hotdog N' Fries", "Smoked sausages, Hotdog Rolls with seasoned Fries.", "", "Smoked Sausage Hotdog, Seasoned Fries", "", 345.60,},
{"Chicken Feet Soup", "Chicken feet soup, with boiled dumplings", "yellow yam, sweet potato and 5 slices garlic bread.", "Chicken soup- Boiled Dumplings, Yellow", "Yam, Sweet Potato, 5 Garlic Bread", 445.60}
};
const MenuData dinner [NUM_DINNER_ITEMS]= {
{"Sunday Dinner", "Fried Chicken served with rice and peas and macaroni salad", "", "Fried Chicken, Rice and Peas, Macaroni Salad", "", 600.00,},
{"Pastas N' Such", "Macaroni casserole topped with an assortment of cheese","served with mashed potatoes and baked chicken", "Macaroni Casserole, Four Cheese Topping", "Mashed Potatoes, Baked Chicken", 450.00,},
{"Real Jamaican Dinner", "Ackee and saltfish served with boiled dumplings", "yam and irish potatoes", "Ackee and Saltfish, Boiled dumplings, Yam", "", 395.00,}
};
const MenuData dessert [NUM_DESSERT_ITEMS]= {
{"Rock Cakes","", "", "Rock Cakes", "", 70.00,},
{"Gizzarda", "", "", "Gizzarda", "", 95.50,},
{"Fruit Cake", "", "", "Fruit Cake", "", 200.00,},
{"Apple Pie Slice", "", "", "Apple Pie Slice", "", 300.00,},
{"Cheese Cake Slice", "","", "Cheese Cake Slice", "", 300.00,},
{"Fudge Cupcake", "","", "Fudge Cupcake", "", 100.00,}
};
const MenuData beverage [NUM_BEVERAGE_ITEMS]= {
{"Hot Chocolate", "", "", "Hot Chocolate", "", 60.00,},
{"Coffee", "", "", "Coffee", "", 50.00,},
{"Soft Drink", "", "", "Soft Drink", "", 90.00,},
{"Beer", "", "", "Beer", "", 150.00,},
{"Wine", "", "", "Wine", "", 250.00,},
{"Water", "", "", "Water", "", 75.00,}
};
/*End of initialization*/
struct customerInfo {
int customer_num;
char cashier_name[20], client_name[20];
}; typedef struct customerInfo info;
/*Fuction Declarations*/
void interface ();
int orderFunction (const MenuData menu[], int);
float Subtotal (const MenuData menu[], int, int);
void Caltotal (float);
void printReceipt (const MenuData menu[], int, float);
enum options {
opt1= 1,
opt2= 2,
opt3= 3,
opt4= 4,
opt5= 5,
opt6= 6
};
enum MenuTime {
Breakfast=1,
Lunch=2,
Dinner=3,
Dessert=4,
Beverage=5,
Receipt=6,
Exit=7
};
/* display any menu data */
void displayMenu(const MenuData menu[], int numofitems)
{
int i;
printf("\n");
for(i=0; i<numofitems; i++) {
printf("%d. %s \n", i+1, menu[i].name);
printf("Description: %s \n", menu[i].desc[0]);
if( strlen(menu[i].desc[1]) > 0 )
printf("%s \n", menu[i].desc[1]);
printf("Price: $%.2f \n", menu[i].price);
printf("\n");
}
}
int main ()
{
interface ();
info in1;
int ch;
MenuData menu;
int password, mmchoice, count=3;
enum MenuTime Mchoice;
for (int i=0; i<count; i++)
{
printf ("\n\t\tEnter Your Cashier Name: ");
scanf ("%s", in1.cashier_name);
printf ("\n");
printf ("\n\t\tEnter the Password: ");
scanf ("%d", &password);
system ("cls");
if (password== PASSWORD)
{
interface ();
FILE *cfPtr;
if ((cfPtr= fopen ("Food.txt", "a"))==NULL)
{
printf ("File could not be opened\n");
}
printf ("\n");
printf ("Enter the Client's name\n:");
scanf ("%s", in1.client_name);
printf ("Enter the Client's Table number\n:");
scanf ("%d", &in1.customer_num);
fprintf (cfPtr, "\n");
fprintf (cfPtr, "Customer Name: %s\n", in1.client_name);
fprintf (cfPtr, "Table Number: %d\n", in1.customer_num);
while (1)
{
system ("cls");
interface ();
printf ("\n");
printf ("---------------#Welcome to Main Menu#----------------\n");
printf ("\n");
printf ("\tPress 1 for the Breakfast Menu\n");
printf ("\tPress 2 for the Lunch Menu\n");
printf ("\tPress 3 for the Dinner Menu\n");
printf ("\tPress 4 for the Desert Menu\n");
printf ("\tPress 5 for the Beverage Menu\n");
printf ("\tPress 6 to Exit\n");
scanf ("%d", &Mchoice);
while ((ch = getchar()) != '\n' && ch != EOF);
switch (Mchoice)
{
case Breakfast:
system ("cls");
printf ("\t.........Breakfast Menu............\n");
displayMenu(breakfast, NUM_BREAKFAST_ITEMS);
orderFunction (breakfast, NUM_BREAKFAST_ITEMS);
getch ();
break;
case Lunch:
system ("cls");
printf ("\t.........Lunch Menu..........\n");
displayMenu(lunch, NUM_LUNCH_ITEMS);
orderFunction (lunch, NUM_LUNCH_ITEMS);
getch ();
break;
case Dinner:
system ("cls");
printf ("\t.........Dinner Menu.........\n");
displayMenu (dinner, NUM_DINNER_ITEMS);
orderFunction (dinner, NUM_DINNER_ITEMS);
getch ();
break;
case Dessert:
system ("cls");
printf ("\t.........Desseert Menu.........\n");
displayMenu (dessert, NUM_DESSERT_ITEMS);
orderFunction (dessert, NUM_DESSERT_ITEMS);
getch ();
break;
case Beverage:
system ("cls");
printf (".........Beverage Menu........\n");
displayMenu (beverage, NUM_BEVERAGE_ITEMS);
orderFunction (beverage, NUM_BEVERAGE_ITEMS);
getch ();
break;
case Receipt:
printReceipt (menu, numofitme, subtot);
break;
case Exit:
exit (1);
break;
default:
printf ("This Option Doesn't Exist\n");
break;
} // End Switch
}//End while
}//End if
else
printf ("Invalid Password!\n");
count=count-1;
printf ("You have %d tries left!\n", count);
}//End For
printf ("This program will close.\n");
printf ("\n");
return 0;
} // end main
void interface ()
{
printf ("\t Welcome to Master's Restaurant and Bar!\n");
printf ("\n");
printf (" o8 \n");
printf (" 888 \n");
printf (" ooo. .oo. .ooo. ooo d8b 888oooo. \n");
printf (" 888P'Y88bP'Y88b 888''8p d88' `88b \n");
printf (" 888 888 888 888 888 888 \n");
printf (" 888 888 888 888 888 888 \n");
printf (" o888o o888o o888o d888b `Y8bod8P' \n");
}//End of Interface
int orderFunction (const MenuData menu[], int numofitems)
{
enum options choices;
int i, ch;
int qty;
while ((ch = getchar()) != '\n' && ch != EOF);
printf ("Enter Choice: ");
scanf ("%d", &choices);
if (choices==0|| choices > numofitems)
{
printf ("Invalid Option.\nPress any key to return to Main Menu.");
}
printf ("Enter Quantity: ");
scanf ("%d", &qty);
FILE *cfPtr;
if ((cfPtr= fopen ("Food.txt", "a"))==NULL)
{
printf ("File could not be opened\n");
}
if (choices== opt1 || choices== opt2 || choices== opt3|| choices== opt4 || choices==opt5 || choices== opt6)
{
fprintf (cfPtr, "Prepare: %s\n", menu[choices-1].prepare[0]);
if (strlen(menu[choices-1].prepare[1]) > 0 )
fprintf (cfPtr, "%s\n", menu[choices-1].prepare[1]);
fprintf (cfPtr, "________________________________________________");
fprintf (cfPtr, "________________________________________________\n");
}
fclose (cfPtr);
return qty;
}//End of Function
float Subtotal (const MenuData menu[], int qty, int numofitems)
{
int i;
float subtot=0.00;
float price1;
for(i=0; i<numofitems; i++)
{
price1= menu[i].price*qty;
}
subtot= subtot + price1;
return subtot;
}
void Caltotal (float subtot)
{
float total;
total= subtot* TAX;
}
void printReceipt (const MenuData menu[], int numofitems, float subtot)
{
int i;
float cash_tender;
float change;
system ("cls");
printf (" 8 \n");
printf (" 88 \n");
printf (" 88ooo. \n");
printf (" oo. .o. .oo oo d8b d8' `8b \n");
printf (" 88P'Y88'Y88 88' 88 88 \n");
printf ("o88o o88o d88b `YbodP' \n");
printf ( "\n");
printf (" ** RECIEPT** \n");
printf ("\n");
printf ("\n");
printf ("5 Kingston Road, Lot 5\n");
printf ("\n");
printf ("\n");
printf ("Item Bought Price\n");
for(i=0; i<numofitems; i++)
{
printf ("%s \t$ %.2f\n", menu[i].name, menu[i].price);
printf ("Subtotal $ %.2f\n", subtot;
printf ("TAX $ %.2f\n", Caltotal (subtot));
printf ("Toatl Sale $ %.2f\n", Caltotal (subtot));
printf ("\n");
}
printf ("Enter the cash tendered by customer: ");
scanf ("%f", &cash_tender);
change= total-ctender;
printf ("The change id %.2f", change);
}
Here is the whole program. I changed flush operation to the while loop.