Question
#include #define SALES_TAX 0.07 #define ITALIAN_BEEF 7.99 #define SUB_SANDWITCH 5.99 #define NACHO_SUPREME 6.99 #define MEXICAN_TACO 2.99 #define NACHO_REGULAR 4.99 #define HOT_DOG 2.99 #define SLUSHY 2.49
#include
#define SALES_TAX 0.07
#define ITALIAN_BEEF 7.99
#define SUB_SANDWITCH 5.99
#define NACHO_SUPREME 6.99
#define MEXICAN_TACO 2.99
#define NACHO_REGULAR 4.99
#define HOT_DOG 2.99
#define SLUSHY 2.49
#define MILK_SHAKE 3.49
#define ICE_CREAM 1.79
#define FOUNTAIN_DRINKS 1.00
void displayWelcomeScreen(void);
void displayMenuScreen(void);
int getValidSelection(void);
void getPrice(int, int *, float *);
void getDiscount(float, float, float *);
void printReceipt(float, float, float, float, float);
int main() {
int selection1, selection2, counter;
float first_item_price, second_item_price, total, discount,
total_after_discount, tax, subtotal;
first_item_price = 0;
second_item_price = 0;
total = 0;
discount = 0;
total_after_discount = 0;
tax = 0;
subtotal = 0;
displayWelcomeScreen();
displayMenuScreen();
selection1 = getValidSelection();
getPrice(selection1, &counter, &first_item_price);
printf(" We are currently having a buy one, get one off sale!");
selection2 = getValidSelection();
getPrice(selection2, &counter, & second_item_price);
total = first_item_price + second_item_price;
getDiscount(first_item_price, second_item_price, &discount);
total_after_discount = total - discount;
tax = total_after_discount * SALES_TAX;
subtotal = subtotal + (total_after_discount + tax);
printReceipt(total, discount, total_after_discount, tax, subtotal);
return 0;
}
void displayWelcomeScreen(void) {
int month, day, year;
month = 01;
day = 12;
year = 2023;
printf(" Hello,");
printf(" I'm Md Maruf Hossain.");
printf(" Welcome to my first project!");
printf(" ITS24000 Spring 2023");
printf(" Date: %d/%d/%d ", month, day, year);
return;
}
void displayMenuScreen(void) {
printf(" ----------------------------------");
printf(" ----Welcome to GRAND FOOD!-----");
printf(" -------------Menu:----------------");
printf(" 1. Italian Beef -----> $%8.2f-", ITALIAN_BEEF);
printf(" 2. Sub Sandwitch ----> $%8.2f-", SUB_SANDWITCH);
printf(" 3. Nacho Supreme ----> $%8.2f-", NACHO_SUPREME);
printf(" 4. Mexican Taco -----> $%8.2f-", MEXICAN_TACO);
printf(" 5. Nacho Regular ----> $%8.2f-", NACHO_REGULAR);
printf(" 6. Hot Dog ----------> $%8.2f-", HOT_DOG);
printf(" 7. Slushy -----------> $%8.2f-", SLUSHY);
printf(" 8. Milk Shake -------> $%8.2f-", MILK_SHAKE);
printf(" 9. Ice Cream --------> $%8.2f-", ICE_CREAM);
printf(" 10. Fountain Drinks -> $%8.2f-", FOUNTAIN_DRINKS);
printf(" ----------------------------------");
return;
}
int getValidSelection(void) {
static int valid_items = 0;
int selection;
if (valid_items == 0) {
printf(
" Please enter the number of the item you would like to purchase -> ");
} else {
printf(" Please enter the number of the next item you would like to "
"purchase -> ");
}
do {
scanf("%d", &selection);
if (selection < 1 || selection > 10) {
printf(" Invalid selection. Please select between 1 and 10. ");
} else {
valid_items++;
}
} while (selection < 1 || selection > 10);
return selection;
}
void getPrice(int selection, int *counter, float *price) {
switch (selection) {
case 1:
printf(" Your selected item is Italian Beef!");
*price = ITALIAN_BEEF;
*counter = *counter + 1;
break;
case 2:
printf(" Your selected item is Sub Sandwich!");
*price = SUB_SANDWITCH;
*counter = *counter + 1;
break;
case 3:
printf(" Your selected item is Nacho Supreme!");
*price = NACHO_SUPREME;
*counter = *counter + 1;
break;
case 4:
printf(" Your selected item is Mexican Taco!");
*price = MEXICAN_TACO;
*counter = *counter + 1;
break;
case 5:
printf(" Your selected item is Nacho Regular!");
*price = NACHO_REGULAR;
*counter = *counter + 1;
break;
case 6:
printf(" Your selected item is Hot Dog!");
*price = HOT_DOG;
*counter = *counter + 1;
break;
case 7:
printf(" Your selected item is Slushy!");
*price = SLUSHY;
*counter = *counter + 1;
break;
case 8:
printf(" Your selected item is Milk Shake!");
*price = MILK_SHAKE;
*counter = *counter + 1;
break;
case 9:
printf(" Your selected item is Ice Cream!");
*price = ICE_CREAM;
*counter = *counter + 1;
break;
case 10:
printf(" Your selected item is Fountain Drinks!");
*price = FOUNTAIN_DRINKS;
*counter = *counter + 1;
break;
}
return;
}
void getDiscount(float p1, float p2, float *discount) {
if (p1 < p2)
*discount = p1 / 2;
else
*discount = p2 / 2;
return;
}
void printReceipt(float total, float discount, float total_after_discount,
float tax, float subtotal) {
printf(" ----------------------------------");
printf(" Total: $%8.2f-", total);
printf(" ----------------------------------");
printf(" Discount: $%8.2f-", discount);
printf(" ----------------------------------");
printf(" Total after discount: $%8.2f-", total_after_discount);
printf(" ----------------------------------");
printf(" Tax: $%8.2f-", tax);
printf(" ----------------------------------");
printf(" Subtotal: $%8.2f-", subtotal);
printf(" ----------------------------------");
printf(" THANK YOU! You are all set! Have a GREAT day!");
return;
}
I want to modify this c programming codes to use arrays to keep track of up to 5 customer selections and prices by using arrays instead of atomic variables wherever necessary. You will be passing arrays to your functions and also incorporating loops to get user selections etc. You will still offer the BOGO if they buy 2 items and a Get the Cheapest Item Free sale if they buy 3 or more items.
could you make these modifications inside the following codes?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started