Instructions
Requirements and Specifications
Source Code
#include
#include
#include
#include
// enum for burger types
enum BurgerType { Chicken, Ham, Vegie };
// define struct Burger
struct Burger
{
char receipt_no[5];
int quantity;
float total_price;
enum BurgerType type;
};
// Function to display menu
void display_menu()
{
printf("Welcome to Tasy Burgers\nPlace your order here...\n\t1. Order Burger\n\t2. Cancel\n\t3. Exit\n");
}
int main()
{
// Define constants
const float BURGER_PRICE = 12.0;
const float DISCOUNT = 10; // 10%
// define arrays to store amount of burgers and their receipts
struct Burger burgets[25];
int receipts_number[25];
int receipts_counter = 0;
char receipt_number[5];
int receipt_exists[25];
float order_total;
float order_discount;
// Burger variable
struct Burger burger;
// Create a loop to display menu and get user's input until the user enters the option 3
int menu_option;
int n_burgers;
while (1)
{
display_menu();
printf("Select your option: ");
scanf("%d", &menu_option);
order_discount = 0;
if (menu_option == 1)
{
printf("How many burgers you wish you order?\n");
scanf("%d", &n_burgers);
burger.quantity = n_burgers;
order_total = (float)burger.quantity * BURGER_PRICE;
burger.total_price = order_total;
if (burger.quantity >= 5)
order_discount = (DISCOUNT / 100.0f)*burger.total_price;
// Display
printf("Your total bill value is $%.2f.", burger.total_price);
if (burger.quantity >= 5)
{
printf(" Discount %.2f\%-\t$%.2f\n", DISCOUNT, order_discount);
printf("Final bill is $%.2f\n", burger.total_price - order_discount);
}
else
printf("\n");
receipts_counter++;
strcpy(receipt_number, "B00");
char buffer[2];
sprintf(buffer, "%d", receipts_counter);
strcat(receipt_number, buffer);
strcpy(burger.receipt_no, receipt_number);
printf("Your receipt number is %s.\n", burger.receipt_no);
printf("Please go to a register and make the payment by quoting the Receipt Number.\n");
receipt_exists[receipts_counter - 1] = 1;
}
else if (menu_option == 2)
{
printf("Please enter your receipt number: ");
scanf(" %s", receipt_number);
int n = 0;
char c;
int n_digits = 0;
for (int i = 1; i < 5; i++)
{
c = receipt_number[i];
if (isdigit(c))
{
n_digits += 1;
}
}
for (int i = 1; i < 5; i++)
{
c = receipt_number[i];
if (isdigit(c))
{
n += pow(10, n_digits - i) *(c - '0');
}
}
if (n <= receipts_counter)
{
if (receipt_exists[n - 1] == 1)
{
printf("Your order has been cancelled. Thank you.\n");
receipt_exists[n - 1] = 0;
}
else
printf("There is no order with that code.\n");
}
printf("There is no order with that code.\n");
}
else if (menu_option == 3)
{
printf("Good Bye!");
break;
}
}
}