Ok so I'm trying to write a console app that will take from the user the amount of money due and the amount of money tendered and make change. One of the requirments was to use reference parameters just incase anyone wonders why theyre all over. I have written the code and it works fine right up until you need more than one dime, nickel, penny, or combination therof. For example if one nickel or one dime is due in change it works fine. If one nickel AND one dime is due in change though the program hangs. Also hangs if 2 nickels, 2 dimes, or 2 pennies are due. I tried printing the values before the print function runs just to make sure it was in the change making function which it was. I see no error in the code of that function though. All I can think is that there is some problem with the 0's in the floating point values and I am somehow losing the prcision or something and causing an infinite loop. Anyways, thanks in advance for reading and any help is much appreciated.

Code:#include <iostream> using namespace std; int makeChange(int& fifties, int& twenties, int& tens, int& fives, int& ones, int& quarters, int& dimes, int& nickels, int& pennies, double& change); int printChange(int& fifties, int& twenties, int& tens, int& fives, int& ones, int& quarters, int& dimes, int& nickels, int& pennies, double& originalChange); int main(void) { int quit, fifties, twenties, tens, fives, ones, quarters, dimes, nickels, pennies; double due, tendered, change, originalChange; quit = 0; cout.setf(ios::fixed | ios::showpoint); cout.precision(2); cout << endl << "Welcome to the change maker!" << endl << "This program will accepts the amount due and the amount tendered from the user \nand computes the change due." << endl; //start the menu while(quit != 2) { cout << endl << "Please choose from the following options:" << endl << "1) Compute change." << endl << "2) Quit." << endl; cin >> quit; //if the user selects compute change if(quit == 1) { //init all values back to 0 each time a new transaction begins fifties = twenties = tens = fives = ones = quarters = dimes = nickels = pennies = 0; due = tendered = change = originalChange = 0.00; //prompt the user for the amount due and validate to make sure its greater than 0 cout << "Please enter the amount due:" << endl; cin >> due; if(due <= 0.00) { cout << "Error: The amount due must be greater than 0.00" << endl; } //prompt the user for the amount tendered and validate to make sure its greater than 0 cout << "Please enter the amount tendered:" << endl; cin >> tendered; if(tendered <= 0.00) { cout << "Error: The amount tendered must be more than 0.00" << endl; } //find the change due by subtracting due from tendered. Validate the change to make sure its greater than 0 change = tendered - due; if(change == 0.00) { cout << "Change due is 0.00. Nothing to compute." << endl; } else if(change < 0.00) { cout << "Error: The amount tendered must be more than the amount due." << endl; } else { //if change is due //store a copy of change due for the final print originalChange = change; //run the makechange function passing the denominations and change due by reference makeChange(fifties, twenties, tens, fives, ones, quarters, dimes, nickels, pennies, change); /*some leftover code I was using to decide if a problem was in makeChange or printChange cout << fifties << endl << twenties << endl << tens << endl << fives << endl << ones << endl << quarters << endl << dimes << endl << nickels << endl << pennies << endl;*/ //run the printChange function passing the denominations and the originalChange by reference printChange(fifties, twenties, tens, fives, ones, quarters, dimes, nickels, pennies, originalChange); } //validate the menu choice to make sure a 1 or a 2 was selected } else if((quit != 1) && (quit != 2)) { cout << "Error: You have entered an invalid menu option." << endl; } } return 0; } //the makeChange function is basically just a loop that tests the ammount of change due to see what the greatest //denomination is that can be subtracted from it. When it finds that denomination it subtracts the value of that //denomination and incriments the denominations counter by 1. Then loops again. It continues looping until the //change due is 0.00. int makeChange(int& fifties, int& twenties, int& tens, int& fives, int& ones, int& quarters, int& dimes, int& nickels, int& pennies, double& change) { while(change > 0.00) { if(change >= 50.00) { change -= 50.00; fifties++; } else if(change >= 20.00) { change -= 20.00; twenties++; } else if(change >= 10.00) { change -= 10.00; tens++; } else if(change >= 5.00) { change -= 5.00; fives++; } else if(change >= 1.00) { change -= 1.00; ones++; } else if(change >= .25) { change -= .25; quarters++; } else if(change >= .10) { change -= .10; dimes++; } else if(change >= .05) { change -= .05; nickels++; } else if(change >= .01) { change -= .01; pennies++; } } return 0; } //the printChange function takes the counters for each denomination and the original change as arguments. //It tests each counter to see if that counters value is greater than 0. If it is greater than 0 it prints //the name of the denomination and the value of the counter. int printChange(int& fifties, int& twenties, int& tens, int& fives, int& ones, int& quarters, int& dimes, int& nickels, int& pennies, double& originalChange){ cout << endl << "The change due is: " << originalChange << endl << "Please make this change using the following: " << endl; if(fifties != 0) { cout << fifties << " fifties" << endl; } if(twenties != 0) { cout << twenties << " twenties" << endl; } if(tens != 0) { cout << tens << " tens" << endl; } if(fives != 0) { cout << fives << " fives" << endl; } if(ones != 0) { cout << ones << " ones" << endl; } if(quarters != 0) { cout << quarters << " quarters" << endl; } if(dimes != 0) { cout << dimes << " dimes" << endl; } if(nickels != 0) { cout << nickels << " nickels" << endl; } if(pennies != 0) { cout << pennies << " pennies" << endl; } return 0; }