I am making a program called "The Vending Machine" in my C++ class and everything works properly except for one output that's when I use Dollar + Quarter + Quarter, which is supposed to be $1.50 and then the loop should die but it won't. So i was hoping maybe someone here sees something I can't see. The function of this program is to simulate a vending machine where you put in coins (Dollars, quarters, dimes and nickels) until you have enough to buy the candy. When you have enough it is suppose to give you the candy and tell you how much change you get in return.
#include <iostream>
using namespace std;
void countMoney(double change); // þetta fall sér um að telja peninga.
double changeLeft(double money_total); // þetta fall sér um að reikna út afganginn af peningnum
int main()
{
int a = 0;
countMoney(a);
return 0;
}
void countMoney(double change) {
double dollar=1.00, quarter=0.25, dime=0.10, nickel=0.05;
double money_total=0.00;
char answer;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
do {
cout << "A packet of candie costs $1.50. You have inserted $" << money_total << "." << endl;
cout << "Please insert coins:" << endl;
cout << " n - Nickel" << endl
<< " d - Dime" << endl
<< " q - Quarter" << endl
<< " D - Dollar" << endl;
cin >> answer;
if(answer == 'D')
money_total += dollar;
else if(answer == 'q')
money_total += quarter;
else if(answer == 'd')
money_total += dime;
else if(answer == 'n')
money_total += nickel;
else
cout << "\'" << answer << "\' is not a valid coin." << endl;
} while(money_total <= 1.50);
cout << "Enjoy your candies. Your change is $" << changeLeft(money_total) << ". Please visit again." << endl;
}
double changeLeft(double money_total) {
double change;
change = money_total - 1.50;
return change;
}