Making Change

I'm currently making a soda machine program. The user enters change, selects an available beverage and then change is returned. I'm in the process on figuring out how to make change and I'm sooo stuck. Not a clue where to begin. Here is my program I have written at the moment...

#include <iostream>
#include <iomanip>
using namespace std;


bool drinkInStock( int numDrink1, int numDrink2, int numDrink3, int userChoice );



bool canMakeChange( int bankQuarters, int bankDimes, int bankNickels,
int newQuarters, int newDimes, int newNickels );


void makeChange ( int &bankQuarters, int &bankDimes, int &bankNickels,
int newQuarters, int newDimes, int newNickels,
int &returnQuarters, int &returnDimes, int &returnNickels );



void updateStock( int &numDrink1, int &numDrink2, int &numDrink3, int userChoice );



int main () {

int bankQuarters = 2; // number of quarters in the machine
int bankDimes = 2; // number of dimes in the machine
int bankNickels = 2; // number of nickels in the machine

int numDrink1 = 2; // num of drink1's in the machine
int numDrink2 = 2; // num of drink2's in the machine
int numDrink3 = 2; // num of drink2's in the machine

int choice; // the user's choice of drink

int newQuarters; // the num of quarters the user enters
int newDimes; // the num of dimes the user enters
int newNickels; // the num of nickels the user enters

int returnQuarters = 0; // the num of quarters returned as change to the user
int returnDimes = 0; // the num of dimes returned as change to the user
int returnNickels = 0; // the num of nickels returned as change to the user

while( true )
{
cout << "Welcome to Coke Machine 1.0" << endl
<< "Enter the number of quarters, dimes, and nickels you wish to enter:" << endl;

cin >> newQuarters >> newDimes >> newNickels;

if( newQuarters == 0 && newDimes == 0 && newNickels == 0 )
break;

cout << "you entered $" << fixed<< setprecision(2) << (newQuarters*25 + newDimes*10 + newNickels*5 )/ 100.0 << endl;
if( (newQuarters*25 + newDimes*10 + newNickels*5 ) < 65 )
{
cout<< "You did not enter enough money" <<endl<<endl;
continue;
}



if(canMakeChange(bankQuarters, bankDimes, bankNickels, newQuarters, newDimes, newNickels))
{
cout << "Drinks: " << endl
<< "1: Coke " << endl
<< "2: Sprite " << endl
<< "3: Dr. Pepper " << endl
<< "Enter your drink choice: " << endl;

cin >> choice;
drinkInStock(numDrink1, numDrink2, numDrink3, choice);

updateStock(numDrink1, numDrink2, numDrink3, choice);

makeChange(bankQuarters, bankDimes, bankNickels, newQuarters, newDimes, newNickels,
returnQuarters, returnDimes, returnNickels);
}
else
{
cout << "Sorry, I cannot provide change." << endl;
}





// Your should not have to enter any code after this point (but its OK if you do)

// print state
cout << "========================\nState:\n"
<< "Coke: " << numDrink1 << endl
<< "Sprite: " << numDrink2 << endl
<< "Dr. Pepper: " << numDrink3 << endl
<< "Quarters: "<< bankQuarters << endl
<< "Dimes: "<< bankDimes << endl
<< "Nickels: "<< bankNickels << endl
<< "=========================" << endl << endl;
}

return 0;
}




// This function takes the number of drinks in stock and the user's choice of drink
// if the choice is in stock, it returns a true, otherwise it returns false
bool drinkInStock( int numDrink1, int numDrink2, int numDrink3, int userChoice )
{
if( userChoice == 1 && numDrink1 > 0)
{
return true;
}
else if( userChoice == 2 && numDrink2 > 0)
{
return true;
}
else if( userChoice == 3 && numDrink3 > 0)
{
return true;
}
else
{
return false;
}
}






// The first three parameters indicate the money in the machine
// the second three indicate the money the user has entered
// returns true if change can be made, false otherwise
bool canMakeChange( int bankQuarters, int bankDimes, int bankNickels,
int newQuarters, int newDimes, int newNickels )
{
if ( ((newQuarters*25 + newDimes*10 + newNickels*5) - 65) < (bankQuarters*25 + newDimes*10 + newNickels*5))
{
return true;
}
else
{
return false;
}

}


//input parameters - positive integers
// The first three parameters indicate the money in the machine
// the second three indicate the money the user has entered
// the last three indicate the change (if any) that will be returned
// If the machine can make change, it updates the values in the bank, and
// calculates the number of quarters, dimes, and nickels to return to the user
//returns true there is enouch change to return to the user, false otherwise

void makeChange ( int &bankQuarters, int &bankDimes, int &bankNickels,
int newQuarters, int newDimes, int newNickels,
int &returnQuarters, int &returnDimes, int &returnNickels )
{
int returnChange;

if ( ((newQuarters*25 + newDimes*10 + newNickels*5) - 65) > (bankQuarters*25 + newDimes*10 + newNickels*5))
{



}


// updates the stock of drinks depending on what the user chose
void updateStock( int &numDrink1, int &numDrink2, int &numDrink3, int userChoice )
{
if(userChoice == 1)
{
numDrink1--;
}
else if(userChoice == 2)
{
numDrink2--;
}
else if(userChoice == 3)
{
numDrink3--;
}

}




I have nothing written under the makeChange function due to the fact that I have no clue where to begin. If someone could help me on just getting started or whatever. Anything would help me at this point!
Making Change? All you have to do is vote for Obama. :)
So in the real world - if you are a cashier, and I give you 1 dollar for goods worth 15 cents - you couldn't work out what change to give me??
Topic archived. No new replies allowed.