I need to display number of bills and coins

Here is the question:
What I need help with is displaying the number of bills and coins.

Write a program that will repeatedly allow the user to determine the change due (the actual
number of bills and coins) on a given purchase for a specified amount tendered that exceeds the
purchase amount. First, the program calls a function input that will prompt for and read in the
purchase amount and the amount of money tendered by the customer (both in dollars, floating point
values), and then determine the change due in dollars (floating point value) and the number of
dollars and cents in change due (integer values). All five of these values should be “returned” via
reference parameters. Next, the program should determine the fewest number of bills (ones, fives,
tens, and twenties) and coins (pennies, nickels, dimes, and quarters) to return to the customer in
change. To do this, the program must use two functions dollars and coins. Function dollars
should determine the minimum number of bills of each denomination in the change and “return”
these numbers. Function coins should determine the minimum number of coins of each
denomination in the change and “return” these numbers. Next, the program should call a function
display that will display all of these values: The purchase amount, the amount tendered, the
change amount, and the minimum number of bills and coins required to make the change. This
function should not use any reference parameters. And finally, the program should ask if the user
wants to determine another change breakdown, and then continue or stop based on the user
response.
Notes:
• The functions that determine the change numbers should “return” the numbers to the
calling module, not display them.
• Assume that the only dollar bills used for change will be $20, $10, $5, and $1.

• Assume that the only coins used for change will be quarters, dimes, nickels, and pennies.
Hint: Use integer quantities to do the calculations necessary to determine the minimum number of
bills and coins: After calculating the float change due amount, convert the change due into cents,
storing the result in an integer variable. (Note: To avoid floating point rounding issues when making
this conversion, include use of the floor function, as described in Part 4 of the notes, to round the
converted value to the nearest integer – i.e., for a float value x, floor(x+0.5) will return x
rounded to the nearest integer.) Then, use this value, along with the integer division and modulus
operators, to determine the number of dollars and cents in the change, storing these values in integer
variables. Then, use these values, along with the integer division and modulus operators, to
determine the minimum number of bills and coins required to make the change.
Here is an example of what output should look like from running your program (user input is shown
in bold):
Enter purchase amount: $100.06
Enter amount tendered: $200
Amount of purchase: $100.06
Amount tendered: $200.00
Change due: $99.94
Bills:
4 - $20's 1 - $10's 1 - $5's 4 - $1's
Coins:
3 - quarter(s) 1 - dime(s) 1 - nickel(s) 4 – penny(ies)
Continue (y or n)? y
Enter purchase amount: $7.89
Enter amount tendered: $10
Amount of purchase: $7.89
Amount tendered: $10.00
Change due: $2.11
Bills:
0 - $20's 0 - $10's 0 - $5's 2 - $1's
Coins:
0 - quarter(s) 1 - dime(s) 0 - nickel(s) 1 – penny(ies)
Continue (y or n)? n

Here is what I have soo far.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  #include <iostream>
using namespace std;

void input(float& purchaseamount, float& amounttendered, float& changedue, int& dollarchange,int& centchange);
void dollars(int& ones,int& tens, int& fives, int& twenties, int dollarchange);
void coins(int& pennies, int& nickles, int& dimes,int& quarters, int centchange);

int main()
{	
	float purchaseamount, amounttendered, changedue;
	int dollarchange, centchange, ones, fives, tens, twenties, pennies, nickles, dimes, quarters;
	char ans;
	do
	{
	
	input(purchaseamount,amounttendered, changedue,  dollarchange, centchange);
	dollars(ones, tens, fives,twenties, dollarchange);
	coins (pennies, nickles, dimes, quarters, centchange);
	
	cout<<"Enter another time (y or n)? ";
	cin>>ans;
	}while(ans == 'y'); 
	return 0;
	
}
void input(float& purchaseamount, float& amounttendered, float& changedue, int& dollarchange,int& centchange)
{
	cout<<"Enter purchase amount: $"; cin>> purchaseamount;
	cout<<"Enter amount tendered: $"; cin>> amounttendered;
	
	changedue = amounttendered - purchaseamount;
	
	cout<< "Amount of Purchase: $" <<purchaseamount<<endl;
	cout<<"Amount tendered: $"<< amounttendered<<endl;
	cout<<"Change due: $"<<changedue<<endl;
	
	dollarchange = changedue/1;
	centchange = changedue*100 - dollarchange*100;
	
	cout<<dollarchange<<endl;
	cout<<centchange<<endl;
		
}
void dollars(int& ones, int& tens,int& fives, int& twenties, int dollarchange)
{
	twenties = dollarchange/20;
	dollarchange = dollarchange- twenties*20;
	
	tens = dollarchange/10;
	dollarchange- dollarchange-tens*10;
	
	fives = dollarchange/5;
	dollarchange = dollarchange - fives*5;
	
	ones= dollarchange;
}

void coins(int& pennies, int& nickles,int& dimes, int& quarters,int centchange)
{
	quarters = centchange/25;
	centchange = centchange- quarters*25;
	
	dimes = centchange/10;
	centchange = centchange- dimes*10;
	
	nickles = centchange/5;
	centchange = centchange-nickles*5;
	
	pennies= centchange;
}
Nvm I solved it myself.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
using namespace std;

void input(float& purchaseamount, float& amounttendered, float& changedue, int& dollarchange,int& centchange);
void dollars(int& ones,int& tens, int& fives, int& twenties, int dollarchange);
void coins(int& pennies, int& nickles, int& dimes,int& quarters, int centchange);
void outputs(int ones, int tens, int fives, int twenties, int pennies, int nickels, int dimes, int quarters);

int main()
{	
	float purchaseamount, amounttendered, changedue;
	int dollarchange, centchange, ones, fives, tens, twenties, pennies, nickles, dimes, quarters;
	char ans;
	do
	{
	
	input(purchaseamount,amounttendered, changedue,  dollarchange, centchange);
	dollars(ones, tens, fives,twenties, dollarchange);
	coins (pennies, nickles, dimes, quarters, centchange);
	outputs(ones, tens, fives, twenties, pennies, nickles, dimes, quarters);
	
	cout<<"Continue (y or n)? ";
	cin>>ans;
	}while(ans == 'y'); 
	return 0;
	
}
void input(float& purchaseamount, float& amounttendered, float& changedue, int& dollarchange,int& centchange)
{
	cout<<"Enter purchase amount: $"; cin>> purchaseamount;
	cout<<"Enter amount tendered: $"; cin>> amounttendered;
	
	changedue = amounttendered - purchaseamount;
	
	cout<< "Amount of Purchase: $" <<purchaseamount<<endl;
	cout<<"Amount tendered: $"<< amounttendered<<endl;
	cout<<"Change due: $"<<changedue<<endl;
	
	dollarchange = changedue/1;
	centchange = changedue*100 - dollarchange*100;
		
}
void dollars(int& ones, int& tens,int& fives, int& twenties, int dollarchange)
{
	twenties = dollarchange/20;
	dollarchange = dollarchange- twenties*20;
	
	tens = dollarchange/10;
	dollarchange- dollarchange-tens*10;
	
	fives = dollarchange/5;
	dollarchange = dollarchange - fives*5;
	
	ones= dollarchange;
}

void coins(int& pennies, int& nickles,int& dimes, int& quarters,int centchange)
{
	quarters = centchange/25;
	centchange = centchange- quarters*25;
	
	dimes = centchange/10;
	centchange = centchange- dimes*10;
	
	nickles = centchange/5;
	centchange = centchange-nickles*5;
	
	pennies= centchange;
}
void outputs(int ones, int tens, int fives, int twenties, int pennies, int nickles, int dimes, int quarters)
{

	cout<<"Bills:"<<endl<<twenties<<" - $20's  "<<tens<<" - $10's  "<<fives<<" - $5's  "<<ones<<" - $1's"<<endl;
	cout<<"Coins:"<<endl<<quarters<<" - quarter(s) "<<dimes<<" - dime(s)  "<<nickles<<" - nickle(s)  "<<pennies<<" - pennie(s)"<<endl;
}
Topic archived. No new replies allowed.