I am supposed to write a program that takes in the amount of each type of donut the user wants (regular or fancy), calculate the price, and then calculate how much money the user should receive back depending on what they paid with.
I have completed the first part of the problem and can successfully calculate the price of the donuts the user wants. I am now trying tell the user how much change they will get, but when I wrote the first if statement to return that the exact payment has been made if the customer pays exactly what is owed it does not print the result to the screen. I want to figure this part out before moving on to the next part.
#include <iostream>
using namespace std;
int main() {
const double TAX = .075;
const double REGPRICE = 0.75;
const double REGDOZENPRICE = 7.99;
const double FANCYPRICE = 0.85;
const double FANCYDOZENPRICE = 8.49;
int regular = 0, fancy = 0;
double price = 0, payment = 0, change = 0;
double costOfFancy = 0, costOfRegular = 0;
cout << "Number of regular donuts ordered: " << endl;
cin >> regular;
// calculate cost of regular donuts if donut amount is between 0 and 12
if (regular < 12 && regular > 0) {
costOfRegular = regular * REGPRICE;
}
// calculate cost of regular donuts if donut amount is greater than 12
else if (regular >= 12) {
int regDozen = regular / 12;
int regInd = regular % 12;
costOfRegular = (regDozen * REGDOZENPRICE) + (regInd * REGPRICE);
}
// set regular donut cost to 0 if 0 regular donuts are ordered
else {
costOfRegular = 0;
}
cout << "Number of fancy donuts ordered: " << endl;
cin >> fancy;
// calculate cost of fancy donuts if donut amount is between 0 and 12
if (fancy < 12 && fancy > 0) {
costOfFancy = fancy * FANCYPRICE;
}
// calculate cost of fancy donuts if donut amount is greater than 12
else if (fancy >= 12) {
int fancyDozen = fancy / 12;
int fancyInd = fancy % 12;
costOfFancy = (fancyDozen * FANCYDOZENPRICE) + (fancyInd * FANCYPRICE);
}
// set fancy donut cost to 0 if 0 fancy donuts are ordered
else {
costOfFancy = 0;
}
// add cost of fancy donuts and regular donuts together and add tax to calculate final cost
double totalCost = (costOfFancy + costOfRegular) + ((costOfFancy + costOfRegular) * TAX);
cout << "Customer owes " << totalCost << endl;
cout << "Customer pays " << endl;
cin >> payment;
if (payment == totalCost) {
cout << "Exact payment received - no change owed" << endl;
}
return 0;
}
For example if the user orders 1 regular donut and 1 fancy donut the amount due is 1.72, and if the user inputs 1.72 as their payment nothing returns.