Using pointers in class
<p>Hi all I have an unusual problem here. I wrote a moneychanger class that determines the number of bills and coins that are given as change, based on the total amount for a purchase and the amount of money given for the purchase. For example if you were going to buy something for $12.04 and gave a $20 dollar bill you would receive $7.96 in change.  </p>

<p>the output would be: </p>

<pre><code>0 twenty dollar bill(s)  
0 ten dollar bill(s)  
1 5 dollar bill(s)  
2 1 dollar bills(s)  
3 quarter(s)  
2 dime(s)  
1 penny(s)  
</code></pre>

<p><strong>now the thing is that i have to return the numbers of each bill and coin using pointers or references.</strong> </p>

<p>my program has two functions a GetBills which uses pointers to integers to return the number of $20, $10, $5, and $1 bills that are needed for the change.</p>

<p>the other is a GetCoins which again uses pointers to integers to return the number of quarters dimes, nickels, and pennies that are needed for the change.</p>

<p>My problem is this. my GetBills is not storing any values in the pointers but my GetCoins is. if i enter 12.04 for purchase price and 20.00 given amount 
my output is:</p>

<pre><code>0 twenty dollar bill(s)
0 ten dollar bill(s)
0 5 dollar bill(s)
0 1 dollar bills(s)
3 quarter(s)
2 dime(s)
1 penny(s)
</code></pre>

<p>so as you can see some the values for the coins good but not for the bills. What could be causing my pointers in my GetBills to not store the proper values?</p>

<p>here's my shortened code:</p>

<p><em>MoneyChanger.h</em></p>

<pre><code>class MoneyChanger
{
private:
double amountP, amountG, totalChange;
int twenty, ten, five, one, change;
int quarter, dime, nickel, penny;
public:
void GetBills(int *twenties, int *tens, int *fives, int *ones);
void GetCoins(int *quarters, int *dimes, int *nickels, int *pennies);
};
</code></pre>

<p><em>MoneyChanger.cpp</em></p>

<pre><code>void MoneyChanger::setData(double pp, double given)
{
amountP = pp;
amountG = given;
CalcChange();
}
void MoneyChanger::CalcChange()
{
 while(totalChange &gt;= 20){totalChange = totalChange-20; twenty++;}
 while(totalChange &gt;= 10){totalChange = totalChange-10; ten++;}
 while(totalChange &gt;= 5){totalChange = totalChange-5; five++;}
 while(totalChange &gt;= 1){totalChange = totalChange-1; one++;}
 while(totalChange &gt;= .25){totalChange = totalChange-.25; quarter++;}
 while(totalChange &gt;= .10){totalChange = totalChange-.10; dime++;}
 while(totalChange &gt;= .05){totalChange = totalChange-.05; nickel++;}
 while(totalChange &gt;= .01){totalChange = totalChange-.01; penny++;}

}
double MoneyChanger::GetTotalChange()
{
totalChange = amountG - amountP;
    return totalChange;
}
void MoneyChanger::GetBills(int *twenties, int *tens, int *fives, int *ones)
{
*twenties = twenty;
*tens = ten;
*fives = five;
*ones = one;
CalcChange();
}
void MoneyChanger::GetCoins(int *quarters, int *dimes, int *nickels, int *pennies)
{
*quarters = quarter;
    *dimes = dime;
*nickels = nickel;
*pennies = penny;
CalcChange();
 }
</code></pre>

<p><em>Main.cpp</em></p>

<pre><code>int main()
{
MoneyChanger mc;
int twenties, tens, fives, ones, quarter, dimes, nickels, pennies;
double purchase, given;
cout&lt;&lt;"please enter total cost of purchase: ";
cin&gt;&gt;purchase;
cin.ignore();
cout&lt;&lt;"\nplease enter amount given: ";
cin&gt;&gt;given;
mc.setData(purchase, given);
cin.ignore();
cout&lt;&lt;"Your change is: "&lt;&lt;mc.GetTotalChange()&lt;&lt;"\n\n";

mc.GetBills(&amp;twenties, &amp;tens, &amp;fives, &amp;ones);
mc.GetCoins(&amp;quarter, &amp;dimes, &amp;nickels, &amp;pennies);

cout&lt;&lt;twenties&lt;&lt;" twenty dollar bill(s)"&lt;&lt;endl;
cout&lt;&lt;tens&lt;&lt;" ten dollar bill(s)"&lt;&lt;endl;
cout&lt;&lt;fives&lt;&lt;" five dollar bill(s)"&lt;&lt;endl;
cout&lt;&lt;ones&lt;&lt;" one dollar bill(s)"&lt;&lt;endl;
cout&lt;&lt;quarter&lt;&lt;" quarter(s)"&lt;&lt;endl;
cout&lt;&lt;dimes&lt;&lt;" dime(s)"&lt;&lt;endl;
cout&lt;&lt;nickels&lt;&lt;" nickel(s)"&lt;&lt;endl;
cout&lt;&lt;pennies&lt;&lt;" penny(s)"&lt;&lt;endl;
return 0;
}
</code></pre>
