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;
// 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;
// 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!