I was to write a code to calculate the total meal for a customer and then give them the total number of 20s, 10s, 5s, 1s, quarters, dimes, nickels, and pennies. I had to use function and within my function to calculate the change i used a do while loop. When i call my change_received function within main, anything listed after the amount given is not displayed my code just stops and i cannot do anything but exit the debugging window. Here's my full code. Please help!!
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
float taxcalc(float, float, float, float);
void rec_tips(float, float, float, float);
void cash_received(float&);
void change_received(float, int&, int&, int&, int&, int&, int&, int&, int&, float, float);
int main()
{
float meal_total, tax_percent, tax, total_taxedBill, recommended_tips1, recommended_tips2, recommended_tips3, amountGiven, change=0;
int twenties = 0, tens = 0, fives = 0, ones = 0, quarters = 0, dimes = 0, nickels = 0, pennies = 0;
cout << "Please enter total bill for food, including food and beverage. ";
cin >> meal_total;
do
{
cout << "Please enter total sales tax percent. ";
cin >> tax_percent;
if (tax_percent > 2.7 && tax_percent <= 14)
{
break;
}
else
cout << "The tax percent entered is invalid. Please re-enter tax between 2.8 and 14.";
} while (1);
tax = tax_percent / 100;
total_taxedBill = meal_total + meal_total*tax;
taxcalc(total_taxedBill, tax_percent, tax, meal_total);
recommended_tips1 = (total_taxedBill * 15) / 100;
recommended_tips2 = (total_taxedBill * 18) / 100;
recommended_tips3 = (total_taxedBill * 20) / 100;
rec_tips(total_taxedBill, recommended_tips1, recommended_tips2, recommended_tips3);
cout << "\n\n";
cout << "Meal Total = " << fixed << setprecision(2) << meal_total << endl;
cout << "Tax Amount = " << fixed << setprecision(2) << meal_total*tax << endl;
cout << "=======================" << endl;
cout << "Total bill = " << fixed << setprecision(2) << total_taxedBill << endl;
cout << "15% tip " << fixed << setprecision(2) << recommended_tips1 << endl;
cout << "18% tip " << fixed << setprecision(2) << recommended_tips2 << endl;
cout << "20% tip " << fixed << setprecision(2) << recommended_tips3 << endl;
cash_received(amountGiven);
cout << "\nAmount of money given: " << fixed << setprecision(2) << amountGiven;
change = amountGiven - total_taxedBill;
cout << "\nChange due: " << fixed << setprecision(2) << change;
change_received(change, twenties, tens, fives, ones, quarters, dimes, nickels, pennies, amountGiven, total_taxedBill);
if (twenties > 0)
cout << "Number of twenties: " << twenties << endl;
if (tens > 0)
cout << "Number of tens: " << tens << endl;
if (fives > 0)
cout << "Number of fives: " << fives << endl;
if (ones > 0)
cout << "Number of ones: " << ones << endl;
if (quarters > 0)
cout << "Number of quarters: " << quarters << endl;
if (nickels > 0)
cout << "Number of dimes: " << dimes << endl;
if (dimes > 0)
cout << "Number of nickels: " << nickels << endl;
if (pennies > 0)
cout << "Number of pennies: " << pennies << endl;
system("pause");
return 0;
}
float taxcalc(float total_taxedBill, float tax_percent, float tax, float meal_total)
{
tax = tax_percent / 100;
total_taxedBill = meal_total + meal_total*tax;
return (total_taxedBill);
}
void rec_tips(float total_taxedBill, float recommended_tips1, float recommended_tips2, float recommended_tips3)
{
recommended_tips1 = (total_taxedBill * 15) / 100;
recommended_tips2 = (total_taxedBill * 18) / 100;
recommended_tips3 = (total_taxedBill * 20) / 100;
return;
}
void cash_received(float& amountGiven)
{
cout << "Please enter the amount of cash received from customer. ";
cin >> amountGiven;
do
{
if (amountGiven > 0 && amountGiven <= 300)
break;
else
cout << "Cash given by customer cannot exceed 300 and has to be greater than 0";
} while (1);
return;
}
void change_received(float change, int& twenties, int& tens, int& fives, int& ones, int& quarters, int& dimes, int& nickels, int& pennies, float amountGiven, float total_taxedBill)
{
do
{
if (change >= 19.99)
{
twenties += 1;
change - 20;
}
if (change >= 9.99)
{
tens += 1;
change - 10;
}
if (change >= 4.99)
{
fives += 1;
change - 5;
}
if (change > .99)
{
ones += 1;
change - 1;
}
if (change > .2499)
{
quarters += 1;
change - .25;
}
if (change > .999)
{
dimes += 1;
change - .10;
}
if (change > .499)
{
nickels += 1;
change - .05;
}
if (change > .099)
{
pennies += 1;
change - .01;
}
}while (change > 0)
return;
}
Please enter total bill for food,including meal and beverage. 13
Please enter total sales tax percent. 10
Meal Total =13.00
Tax amount =1.30
=================
Total bill =14.30
15% tip =2.14
18% tip =2.57
20% tip =2.86
Please enter the amount of cash received from customer. 50
Amount of money given: 50.00
Change due: 35.70