Question: Please check and fix my C++ program. I don't know why my output is different with the expected output. Here is my program or coding:
Please check and fix my C++ program. I don't know why my output is different with the expected output.
Here is my program or coding:
#include
#include
#include
using namespace std;
// Function prototypes
void welcome();
void displayMenu();
void readOption(int &option);
void readInt(string prompt, int &num);
void readDouble(string prompt, double &num);
void placeOrder(double &cost);
double tipDiscount(double &tip, double &discount, double cost);
int main() {
welcome();
int option;
do {
displayMenu();
readOption(option);
if (option == 1) {
double totalCost = 0.0;
placeOrder(totalCost);
double tip, discount;
double finalTotal = tipDiscount(tip, discount, totalCost);
cout cout if (discount > 0.0) {
cout cout }
cout } else if (option != 2) {
cout }
} while (option != 2);
cout return 0;
}
// Function implementations
void welcome() {
cout }
void displayMenu() {
cout cout cout cout }
void readOption(int &option) {
do {
readInt(">> ", option);
if (option != 1 && option != 2) {
cout }
} while (option != 1 && option != 2);
}
void readInt(string prompt, int &num) {
cout cin >> num;
while (!cin || num 2) {
cout cin.clear();
cin.ignore(100, '\n');
cin >> num;
}
cin.ignore(10, '\n');
}
void readDouble(string prompt, double &num) {
cout cin >> num;
while (!cin || num cout cin.clear();
cin.ignore(100, '\n');
cin >> num;
}
cin.ignore(10, '\n');
}
void placeOrder(double &cost) {
char anotherItem;
do {
string itemName;
double itemCost;
cout getline(cin, itemName);
readDouble("Enter the cost of your item $: ", itemCost);
cost += itemCost;
do {
cout cin >> anotherItem;
cin.ignore(10, '\n');
if (tolower(anotherItem) != 'y' && tolower(anotherItem) != 'n') {
cout }
} while (tolower(anotherItem) != 'y' && tolower(anotherItem) != 'n');
} while (tolower(anotherItem) == 'y');
}
double tipDiscount(double &tip, double &discount, double cost) {
readDouble("Enter the amount of tip you want to add $: ", tip);
double total = cost + tip;
if (total > 50.0) {
discount = total * 0.10;
} else if (total > 35.0 && total discount = total * 0.05;
} else {
discount = 0.0;
}
return total - discount;
}
Here is my output ( the one that I highlighted is where are the difference)




Please help me with that. Make sure post your output after fixed.
Enter the name of your item: Fajita Bowl Enter the cost of your item $: 20.75 Do you want another item? (y/n): y Enter the name of your item: Vietnamese plate Enter the cost of your item $: 22.75 Do you want another item? (y/n): y Enter the name of your item: Soda Enter the cost of your item $: 3.50 Do you want another item? (y/n): x Invalid Option! Please choose y or n! Do you want another item? (y/n): n Enter the amount of tip you want to add $: 10.00 Your final total is: $51.30 You get a 5% discount! Your discount is $5.70 Your total after tip and discount is: $45.60 What would you like to do today? Pick an option from below: 1. Place an order 2. Quit >> 2 Thank you for using my program!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
