Code:
#include <stdio.h>
#include <getopt.h>
#include <string.h>
int main()
{
// Menu dictionary
int menu_size = 4;
struct MenuItem menu[4];
menu[0].description = strdup("Fried Chicken");
menu[0].price = 200.0;
menu[1].description = strdup("Baked Chicken");
menu[1].price = 350.0;
menu[2].description = strdup("Jerk Chicken");
menu[2].price = 500.0;
menu[3].description = strdup("Barbecue Chicken");
menu[3].price = 750.0;
// Starting balance
double starting_balance = 100000.0;
double balance = 100000.0;
double chicken_remaining = 425250.0 / 70.0;
// Initialize variables
int total_servings = 0;
int total_orders = 0;
double total_fried_chicken_sales = 0.0;
double total_baked_chicken_sales = 0.0;
double total_jerk_chicken_sales = 0.0;
double total_bbq_chicken_sales = 0.0;
char name[100] = "";
char order_confirmation[2] = "";
// Loop for taking customer orders
while (chicken_remaining > 0) {
// Display menu
printf("Welcome to Keisha's Delicious Chicken\nToday's Menu\n");
for (int i = 0; i < menu_size; i++) {
printf("%d. %s %.2f\n", i + 1, menu[i].description, menu[i].price);
}
printf("5. Type in 'close' to exit the program. \n");
// Take order
while (1) {
printf("Enter customer name: ");
fgets(name, sizeof(name), stdin);
name[strcspn(name, "\n")] = '\0';
if (strcmp(name, "close") == 0) {
printf("\nTotal orders: %d\n", total_orders);
printf("Total servings: %d\n", total_servings);
printf("Total Fried Chicken sales: %.2f (%d servings)\n", total_fried_chicken_sales, (int)(total_fried_chicken_sales/200.0));
printf("Total Baked Chicken sales: %.2f (%d servings)\n", total_baked_chicken_sales, (int)(total_baked_chicken_sales/350.0));
printf("Total Jerk Chicken sales: %.2f (%d servings)\n", total_jerk_chicken_sales, (int)(total_jerk_chicken_sales/500.0));
printf("Total Barbecue Chicken sales: %.2f (%d servings)\n", total_bbq_chicken_sales, (int)(total_bbq_chicken_sales/750.0));
printf("Current balance: %.2f\n", balance);
printf("Chicken remaining: %.2f\n", chicken_remaining);
printf("Thank you for choosing Keisha's Delicious Chicken!\n");
return 0;
}
int choice;
printf("Enter order number (1-4): ");
scanf("%d", &choice);
getchar(); // Consume newline character
if (choice < 1 || choice > menu_size) {
printf("Invalid choice. Please try again.\n");
} else
{
// Compute cost of the order
double order_cost = menu[choice - 1].price;
}
}
}
return 0;
}
Comment