Answer:
Here's an example program in C that fulfills the requirements:
#include <stdio.h>
#define CHICKEN_PRICE 5.00
#define FRITOS_PRICE 3.49
#define BREAD_PRICE 0.03
#define FAJITAS_PRICE 7.99
int main() {
int chicken_qty = 0, fritos_qty = 0, bread_qty = 0, fajitas_qty = 0;
char choice;
float subtotal = 0.0, tax = 0.0, total = 0.0, discount = 0.0;
do {
printf("\\*** My HEB2 ***\\");
printf("1. Chicken - $%.2f\\", CHICKEN_PRICE);
printf("2. Fritos - $%.2f\\", FRITOS_PRICE);
printf("3. Bread - $%.2f\\", BREAD_PRICE);
printf("4. Fajitas - $%.2f\\", FAJITAS_PRICE);
printf("5. Purchase Items\\");
printf("Enter choice (1-5): ");
scanf(" %c", &choice);
switch (choice) {
case '1':
chicken_qty++;
subtotal += CHICKEN_PRICE;
printf("Added 1 chicken to cart.\\");
break;
case '2':
fritos_qty++;
subtotal += FRITOS_PRICE;
printf("Added 1 bag of Fritos to cart.\\");
break;
case '3':
bread_qty++;
subtotal += BREAD_PRICE;
printf("Added 1 loaf of bread to cart.\\");
break;
case '4':
fajitas_qty++;
subtotal += FAJITAS_PRICE;
printf("Added 1 fajitas to cart.\\");
break;
case '5':
break;
default:
printf("Invalid choice. Try again.\\");
break;
}
} while (choice != '5');
if (chicken_qty > 0 && fritos_qty > 0 && bread_qty > 0 && fajitas_qty > 0) {
discount = subtotal * 0.2;
}
printf("\\*** Receipt ***\\");
if (chicken_qty > 0) printf("%d Chicken - $%.2f\\", chicken_qty, chicken_qty * CHICKEN_PRICE);
if (fritos_qty > 0) printf("%d Fritos - $%.2f\\", fritos_qty, fritos_qty * FRITOS_PRICE);
if (bread_qty > 0) printf("%d Bread - $%.2f\\", bread_qty, bread_qty * BREAD_PRICE);
if (fajitas_qty > 0) printf("%d Fajitas - $%.2f\\", fajitas_qty, fajitas_qty * FAJITAS_PRICE);
printf("\\Subtotal: $%.2f\\", subtotal);
if (discount > 0.0) {
printf("20%% Discount: -$%.2f\\", discount);
}
tax = subtotal * 0.0825;
printf("Tax: $%.2f\\", tax);
total = subtotal + tax - discount;
printf("Total: $%.2f\\", total);
return 0;
}
Step-by-step explanation:
This program uses a do-while loop to repeatedly prompt the user for input until they choose to purchase their items (option 5). It keeps track of the quantity of each item selected, as well as the subtotal. If the user purchases at least one