I was given this assignment to create a function and have the user input a number and the function is suppose to give you the amount of change back. My program is listed below
#include<iostream>
using namespace std;
int change(int,int& ,int& ,int& ,int& ,int& ,int& );
int main()
{
int a;
int b;
int c,d,e,f,g,h;
cout<<"Please enter a dollar amount: $";
cin>>b;
a=change(b,c,d,e,f,g,h);
cin.get();
return 0;
}
int change(int x, int& hundreds,int& fifties,int& twenties,int& tens,int& fives,int& ones)
{
hundreds=x/100;
cout<<hundreds<<endl;
fifties=x/50;
cout<<fifties<<endl;
twenties=x/20;
cout<<twenties<<endl;
tens=x/10;
cout<<tens<<endl;
fives=x/5;
cout<<fives<<endl;
ones=x/1;
cout<<ones<<endl;
cin.get();
return 0;
}
If I enter $126 it gives me it gives me the maximum amount of what a hundred or fifty dollar bill can go into it. But the direction says that the function is to consider the integer passed value as a dollar amount and convert the value into the least number of equivalent bills. Using the references, the function should directly alter the respective arguments in the calling function.
I know my program is wrong but I'm not completely understanding the whole reference variables and I'm just completely stuck on how to do it correctly.