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
#include <iostream>
usingnamespace 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;
}
#include <iostream>
usingnamespace 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()
{
}