Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct {
const char *username;
const char *password;
} users[3] = {
{ "yeeted", "animo" },
{ "deleted", "animo" },
{ "dlsu", "animo" },
};
int validateUser(const char *username, const char *password) {
for ( size_t i = 0 ; i < sizeof(users)/sizeof(*users) ; i++ ) {
if ( strcmp(username,users[i].username) == 0 &&
strcmp(password,users[i].password) == 0 ) {
return 1;
}
}
return 0;
}
void login(char *username, char *password) {
printf("*************************************\n");
printf("Enter your username: ");
scanf("%s", username);
printf("***********************************\n");
printf("Enter your password: ");
scanf("%s", password);
}
void signon_banner(void) {
printf("***********************************\n");
printf("Welcome back! You are now logged in! \n");
printf("*************************************\n");
printf("----------------------------------------------------------------------------\n");
printf(" Welcome to Sunny Breakfast Hub!\n");
printf(" Established 2020\n");
printf("------------------------------------------------------------------------------\n");
}
//void (for menu) declarations
void Menu(void);
int Options(void);
void TakeOrder(void);
void OptionsGoingToReceipt(void);
void Receipt(void);
int main()
{
char username[20];
char password[20];
int option = 0;
do {
login(username, password);
if( validateUser(username,password) )
signon_banner();
do {
Menu();
option = Options();
} while ( option != 3 );
} else {
printf("***********************************");
printf("\nUsername or Password is incorrect!");
printf("\nPlease try again! ");
}
} while( option == 0 );
}
struct menuItem {
int code;
const char *name;
int price;
};
#define MAX_MENU_ITEMS 10
struct menu {
const char *name;
struct menuItem items[MAX_MENU_ITEMS];
};
struct menu breakfasts = {
"SUNNY BREAKFAST COMBOS",
{
{ 101, "Chicken 'n Waffles", 200 },
{ 102, "Breakfast Burrito", 230 },
{ 103, "All American Platter", 400 },
{ 104, "Bacon Maniac w/ Eggs", 300 },
{ 105, "Classic Eggs Benedict", 250 },
{ 106, "Sausage Maniac w/ Eggs", 300 },
{ 107, "Fiesta Omelette", 250 },
// the rest are automatically filled with zero
}
};
struct menu sandwiches = {
"ALL DAY SANDWICH",
{
{ 201, "Honey Glazed Ham", 200 },
{ 202, "Tuna Mayo", 200 },
{ 203, "Chicken 'n Cheese", 180 },
{ 204, "Steak 'n Cheese", 250 },
{ 205, "Vegan Delight", 150 },
}
};
struct menu pancakes = {
"GOOD MORNING PANCAKES",
{
{ 301, "Mixed Berries", 180 },
{ 302, "Blueberry", 180 },
{ 303, "Chocolate Chip", 150 },
{ 304, "Banana Walnut", 150 },
}
};
struct menu drinks = {
"SUNNY COFFEE AND REFRESHMENTS",
{
{ 401, "Vanilla Milkshake", 120 },
{ 402, "Cappucino", 120 },
{ 403, "Mocha Frappucino", 100 },
{ 404, "Fresh Orange Juice", 80 },
}
};
void menuHelper(const struct menu *left, const struct menu *right ) {
printf("%-40s %-40s\n", left->name, right->name );
for( int i = 0 ; i < MAX_MENU_ITEMS ; i++ ) {
if ( left->items[i].code != 0 ) {
printf("%3d %-26s P%3d ", left->items[i].code,
left->items[i].name, left->items[i].price );
} else {
printf("%-40s", "" );
}
if ( right->items[i].code != 0 ) {
printf("%3d %-26s P%3d", right->items[i].code,
right->items[i].name, right->items[i].price );
}
printf("\n");
}
}
void Menu(void)
{
printf("=========================================================================\n");
printf(" SUNNY BREAKFAST HUB MENU\n");
printf("=========================================================================\n");
menuHelper(&breakfasts, &sandwiches);
menuHelper(&pancakes, &drinks);
}
int Options(void)
{
int OptionCode;
printf("=============================================================================\n");
printf(" SUNNY BREAKFAST HUB OPTIONS\n");
printf("=============================================================================\n");
printf("01 Back to Menu \n");
printf("02 Take Order\n");
printf("03 Exit Program\n");
printf("Enter the Option Code here: \n");
scanf("%i", &OptionCode);
if( OptionCode == 2 ) {
TakeOrder();
}
return OptionCode;
}
const struct menuItem *findItem(const struct menu *menu, int code ) {
for( int i = 0 ; i < MAX_MENU_ITEMS ; i++ ) {
if ( menu->items[i].code == code )
return &menu->items[i];
}
return NULL;
}
//void function for TakeOrder
void TakeOrder(void)
{
float price = 0;
float TotalPrice = 0;
float SubTotal = 0;
int quantity;
int trial;
int MenuCode;
do {
printf("=============================================================================\n");
printf(" Welcome to Sunny Breakfast Hub's Order Section!\n");
printf("=============================================================================\n");
printf("Please input the Menu Code of your order: ");
scanf("%i", &MenuCode);
// see if the item chosen is in any of the menus
const struct menuItem *item = NULL;
if ( !item ) item = findItem(&breakfasts, MenuCode);
if ( !item ) item = findItem(&sandwiches, MenuCode);
if ( !item ) item = findItem(&pancakes, MenuCode);
if ( !item ) item = findItem(&drinks, MenuCode);
if ( item ) {
printf("You ordered: %s\n", item->name);
printf("Quantity: ");
scanf("%d", &quantity);
price = item->price;
}
SubTotal = price * quantity;
TotalPrice += SubTotal;
printf("Subtotal: P%.2f", price);
printf(" * %i", quantity);
printf(" = P%.2f\n", SubTotal);
printf("Do you want to purchase more?\n");
printf(" -> Press (1) if you want to purchase more.\n");
printf(" -> Press (0) if you want to proceed to checkout options.\n");
printf("Please enter (1/0) here: ");
scanf("%i", &trial);
}
while (trial == 1);
}