Question: PLEASE HELP WILL THUMBS UP!! Need help fixing C++ Code! I am working on functions in C++ Visual studios 2019, However the code I have

PLEASE HELP WILL THUMBS UP!!

Need help fixing C++ Code! I am working on functions in C++ Visual studios 2019, However the code I have keeps coming up with the following errors:

E0020 identifier "TIP" is undefined

E0020 identifier "SHIP_RATE1" is undefined

E0020 identifier "SHIP_RATE2" is undefined

E0020 identifier "SHIP_RATE3" is undefined

C2065 'SHIP_RATE1': undeclared identifier

C2065 'SHIP_RATE2': undeclared identifier

C2065 'SHIP_RATE3': undeclared identifier

This is the code I used:

#include #include

using namespace std;

// Function prototypes void displayMenu(); double tipCalculator(double subtotal); double shippingCalculator(double subtotal);

int main() { const double MILK_PRICE = 5.99, EGG_PRICE = 6.99, CHEESE_PRICE = 10.98, PASTA_PRICE = 2.75; const double TIP = 5.00; const double SHIP_RATE1 = 7.65, SHIP_RATE2 = 4.35, SHIP_RATE3 = 0.00;

int item; double quantity, cost, subtotal = 0, shipping, total; char order_choice, tip_choice;

// Display the menu displayMenu();

do { // Get user's order cout << endl << "Choose an item (1-4): "; cin >> item; cout << "Enter quantity: "; cin >> quantity;

switch (item) { case 1: cost = MILK_PRICE * quantity; break; case 2: cost = EGG_PRICE * quantity; break; case 3: cost = CHEESE_PRICE * quantity; break; case 4: cost = PASTA_PRICE * quantity; break; default: cout << "Invalid item number." << endl; continue; }

// Ask if the user wants to add a tip cout << "Do you want to add a tip? (y/n): "; cin >> tip_choice; if (tip_choice == 'y') { cost += tipCalculator(cost); }

subtotal += cost;

// Ask if the user wants to give another order cout << "Do you want to give another order? (y/n): "; cin >> order_choice; } while (order_choice == 'y');

// Calculate shipping and total total = shippingCalculator(subtotal);

// Display the total cout << fixed << setprecision(2) << endl; cout << "Subtotal: $" << subtotal << endl; cout << "Shipping: $" << total - subtotal << endl; cout << "Total: $" << total << endl;

return 0; }

// Function to display the menu void displayMenu() { cout << "----- GROCERY SHOPPING ITEMS -----" << endl; cout << "1. Milk - $5.99 / gallon" << endl; cout << "2. Egg - $6.99 / dozen" << endl; cout << "3. Cheese - $10.98 / 8oz" << endl; cout << "4. Pasta - $2.75 / packet" << endl; }

// Function to ask if the user wants to add a tip and calculate the subtotal accordingly double tipCalculator(double subtotal) { double tip; cout << "Enter tip amount: $"; cin >> tip; return tip + TIP; }

// Function to calculate the total including a shipping rate based on the subtotal double shippingCalculator(double subtotal) { double shipping, total; if (subtotal <= 20.00) { shipping = SHIP_RATE1; } else if (subtotal > 20.00 && subtotal <= 35.00) { shipping = SHIP_RATE2; } else { shipping = SHIP_RATE3; } total = subtotal + shipping; return total; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!