I am trying to create a program that would help a cashier return change to their customer, it will print out how many hundreds, tens, fives, ones, quarters, dimes, nickels, and pennies.
I am stuck on the quarter part, I can't seem to figure out to print out the correct amount of quarters needed. If i make the quarter a double, it will print out that I need 3.12 quarters (something along the lines of that) and if I make the quarter variable and int, it will sometimes print out that I need 0 quarters.
P.S. I realize I forgot to add the code to return the number of five dollar bills, I will do that later tonight.
#include <iostream>
usingnamespace std;
void changeFunction(double &change)
{
int hundreds;
int tens;
int fives;
int ones;
double quarters;
double dimes;
double nickles;
double pennies;
if (change < 100)
{
tens = change / 10;
cout << "The number of tens you will need is: " << tens << endl;
ones = change - (tens * 10);
cout << "The number of ones you will need is: " << ones << endl;
quarters = change - ((tens * 10) + (ones * 1));
quarters = quarters*100;
quarters = quarters / 25;
cout << "The number of quarters you will need is: " << quarters;
}
if (change >= 100)
{
hundreds = change / 100;
cout << "The number of hundreds you will need is:" << hundreds << endl;
tens = (change-(hundreds*100)) / 10;
cout << "The number of tens you will need is:" << tens << endl;
ones = change - (hundreds * 100 + tens * 10);
cout << "The numner of ones you will need is:" << ones << endl;
}
}
int main()
{
double change;
cout << "Enter a value of money that needs to broken down into change: ";
cin >> change;
changeFunction(change);
system("pause");
return 0;
}