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 getValidSelection1(void);
int getValidSelection2(void);
float getPriceOfItem(int);
float getDiscount(float, float);
void printReceipt(float, float, float, float, float);
int main() {
int selection1, selection2;
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 = getValidSelection1();
first_item_price = getPriceOfItem(selection1);
selection2 = getValidSelection2();
second_item_price = getPriceOfItem(selection2);
total = first_item_price + second_item_price;
discount = getDiscount(first_item_price, second_item_price);
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 getValidSelection1(void) {
int selection1;
do {
printf(
" Please enter the number of the item you would like to purchase -> ");
scanf("%d", &selection1);
if (selection1 < 1 || selection1 > 10) {
printf(" Invalid selection. Please select between 1 and 10. ");
}
} while (selection1 < 1 || selection1 > 10);
return selection1;
}
int getValidSelection2(void) {
int selection2;
do {
printf(" We are currently having a buy one, get one off sale!");
printf(" Select your 2nd item -> ");
scanf("%d", &selection2);
if (selection2 < 1 || selection2 > 10) {
printf(" Invalid selection. Please select between 1 and 10. ");
}
} while (selection2 < 1 || selection2 > 10);
return selection2;
}
float getPriceOfItem(int selection) {
float price = 0;
switch (selection) {
case 1:
printf(" Your selected item is Italian Beef!");
price = ITALIAN_BEEF;
break;
case 2:
printf(" Your selected item is Sub Sandwitch!");
price = SUB_SANDWITCH;
break;
case 3:
printf(" Your selected item is Nacho Supreme!");
price = NACHO_SUPREME;
break;
case 4:
printf(" Your selected item is Mexican Taco!");
price = MEXICAN_TACO;
break;
case 5:
printf(" Your selected item is Nacho Regular!");
price = NACHO_REGULAR;
break;
case 6:
printf(" Your selected item is Hot Dog!");
price = HOT_DOG;
break;
case 7:
printf(" Your selected item is Slushy!");
price = SLUSHY;
break;
case 8:
printf(" Your selected item is Milk Shake!");
price = MILK_SHAKE;
break;
case 9:
printf(" Your selected item is Ice Cream!");
price = ICE_CREAM;
break;
case 10:
printf(" Your selected item is Fountain Drinks!");
price = FOUNTAIN_DRINKS;
break;
default:
printf(" You didn't select any of these things!");
printf(" Select between (1 to 10)! Try again!");
break;
}
return price;
}
float getDiscount(float p1, float p2) {
float discount = 0;
if (p1 < p2)
discount = p1 / 2;
else
discount = p2 / 2;
return discount;
}
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;
}
Modify it by converting sections of the code according to the specifications below.
1. Modify your value-returning function that takes no parameters and prompts the user for a menu selection, checks for its validity, and returns the item selected when valid to have a static local variable that keeps track of how many valid items have been selected. The function will use this static variable to differently prompt the user to make additional selections using a decision structure of your choice (switch(), if-else).
2. Convert your value-returning function that takes the item selected as a parameter and returns the price of the item selected to a function that uses pass-by-reference and takes as parameters a pass-by-value parameter for the item selected and pass-by-reference variable the items price.
3. Convert your value-returning function that takes the prices of the two items selected and returns the discount into a function that uses pass-by-reference that takes the following parameters: total number of items purchased, the price variables for three items, the discount. The discount parameter will be pass-by-reference, all others will be pass-by-value
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