Need help (im bad with classes)

Okay so I made this program that takes 2 numbers(the price of the item and the money you pay with) and its turns everything into mininmun amout of change. Ex Item cost 49.99 I pay with 53 (for some reason) it gives back 2 dollars 3 quarters 2 dimes and 4 pennies (not sure if thats right but you get the point). Now the problem Im having is making everything i have into classes(or object oriented programming or whatever). I started but im stuck and could use any kind of help.
TL:DR I have one .cpp file that needs to be simplified with classes

Original
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <iostream>

using namespace std;



int main()
{
	
	int Hundred_Bill = 0;					//List all of the bills and coins (in an int because they will only be counters)
	int	Fifty_Bill = 0;
	int Twenty_Bill = 0;
	int Ten_Bill = 0;
	int Five_Bill = 0;
	int One_Bill = 0;
	int Quarter = 0;
	int Dime = 0;
	int Nickle = 0;
	int Penny = 0;
	int Total;

	double Price_of_Item, Money_Inputted, Current, temp;               //List of everything than needs to have a "." in it

	cout << "Please type the price of the item you wish to buy: $";                     //Get Price of item
	cin >> Price_of_Item;
	cout << endl;

	cout << "Please type the amount of money you will pay with: $";                    //Gets Amount payed with
	cin >> Money_Inputted;
	cout << endl;

	if (Price_of_Item > Money_Inputted)														//Prevents not paying enough
	{
		cout << "Sorry did not have effecient funds to buy item" << endl;
		return 0;
	}
	
	
	Current = Money_Inputted - Price_of_Item ;	//Subtracts price and payment to start getting change

		while (Current >= 100)				//Check for change involving 100 dollar bill
		{
			Current -= 100;
			Hundred_Bill++;
		
		}

		while (Current >= 50)			//Check for change involving 50 dollar bill
		{
			Current -= 50;
			Fifty_Bill++;
		
		}

		while (Current >= 20)			//Check for change involving 20 dollar bill
		{
			Current -= 20;
			Twenty_Bill++;
		
		}

		while (Current >= 10)			//Check for change involving 10 dollar bill
		{
			Current -= 10;
			Ten_Bill++;
		
		}

		while (Current >= 5)			//Check for change involving 5 dollar bill
		{
			Current -= 5;
			Five_Bill++;
		
		}

		while (Current >= 1)			//Check for change involving 1 dollar bill
		{
			Current -= 1;
			One_Bill++;
		
		}
		
			Quarter = Current / 0.25;            //checks for quartes by dividing the number of natural numbers and keeping it in an int
			temp = Quarter * .25;
			Current = Current - temp;
		
			Dime = Current / 0.10;				//checks for dimes by dividing the number of natural numbers and keeping it in an int
			temp = Dime * .10;
			Current = Current - temp;

			Nickle = Current / 0.05;			//checks for nickles by dividing the number of natural numbers and keeping it in an int
			temp = Nickle * .05;
			Current = Current - temp;

			Current += .001;
			Penny = Current / 0.01;				//checks for pennies by dividing the number of natural numbers and keeping it in an int
			temp = Penny * .01;
			Current = Current - temp;

			Total = Hundred_Bill + Fifty_Bill + Twenty_Bill + Ten_Bill + One_Bill + Quarter + Nickle + Dime + Penny;     //checking to see if any bills or coins have been used if 0 no if anything else yes
			
	if (Total == 0)
	{
		cout << "You broke even :D Have a nice day" << endl; //To prevent the visualization of the "vending" if broken even
		return 0;
	}

	cout << "*Ca-Ching...click click click*" << endl;
	cout << "Your change was: " << endl;

	if (Hundred_Bill >= 1)												// If any of these bills were used the program will go through and tell you how many of the certain bill you had 
	{
		cout << Hundred_Bill << " Hundred Dollar Bill(s)" << endl;  
	}

	if (Fifty_Bill >= 1) 
	{
		cout << Fifty_Bill << " Fifty Dollar Bill(s)" << endl;
	}

	if (Twenty_Bill >= 1) 
	{
		cout << Twenty_Bill << " Twenty Dollar Bill(s)" << endl;
	}
	
	if (Ten_Bill >= 1) 
	{
		cout << Ten_Bill << " Ten Dollar Bill(s)" << endl;
	}
	
	if (Five_Bill >= 1) 
	{
		cout << Five_Bill << " Five Dollar Bill(s)" << endl;
	}

	if (One_Bill >= 1) 
	{
		cout << One_Bill << " One Dollar Bill(s)" << endl;
	}

	if (Quarter >= 1) 
	{
		cout << Quarter << " Quarter(s)" << endl;					// If any of these coins were used the program will go through and tell you how many of the certain coin you had 
	}

	if (Dime >= 1) 
	{
		cout << Dime << " Dime(s)" << endl;
	}
	
	if (Nickle >= 1) 
	{
		cout << Nickle << " Nickle(s)" << endl;
	}

	if (Penny >= 1) 
	{
		cout << Penny << " Pennie(s)" << endl;
	}

	cout << "Thank You :D Have a nice day" << endl;

	return 0;

}


Attempted new code
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
#include <iostream>

using namespace std;


class ChangeMachine {
public:
	ChangeMachine();

	void getDollars(int current);
	void getCoins();


private:
	int Hundred_Bill;					//List all of the bills and coins (in an int because they will only be counters)
	int	Fifty_Bill;
	int Twenty_Bill;
	int Ten_Bill;
	int Five_Bill;
	int One_Bill;
	int Quarter;
	int Dime;
	int Nickle;
	int Penny;
	int Total;
	double Price_of_Item, Money_Inputted, Current, temp;               //List of everything than needs to have a "." in it



};

void ChangeMachine::getDollars(int current) {

	if (current < 100 ){

	}

};

int main()
{
	
	
}
Last edited on
Topic archived. No new replies allowed.