I'm not really sure... Here is what my program looks like so far.
It is supposed to implement a cash register.
The last function (AmountToMakeChangeFor) is supposed to take a parameter placeholder double which represents the amount to make
change for, and fills the number of each denomination correctly, and the program should run like this (based upon how many non-zero amounts of each denomination you should receive in return:
Twenties: 2
Fives: 1
Ones: 1
Quarters: 2
Dimes: 1
Pennies: 3
I am quite baffled by this right now!
Code:
#include <iostream>
using namespace std;
class Change
{
public:
void showEach();
void setEachToZero();
double AmountToMakeChangeFor();
private:
int numTwenties;
int numTens;
int numFives;
int numOnes;
int numQuarters;
int numDimes;
int numNickels;
int numPennies;
};
int main()
{
double amount; // declare a double named "amount" in MAIN
double tender; // declare a double named "tender" in MAIN
cout << "Please enter the amount of the item: "; //asks the user to enter price of item
cin >> amount; // inputs this as "amount"
cout << endl; // end line
cout << "Please enter the amount tendered: "; // asks the user to enter the amount received
cin >> tender; // inputs this as "tender"
cout << endl; // end line
if (tender - amount > 0)
{
double amt_p = tender - amount;
}
else if (tender - amount < 0)
{
double amt_p = 0;
cout << "You owe an additional amount of " << amount - tender << endl;
}
else
{
double amt_p = 0;
cout << "You broke even." << endl;
}
system("pause");
return 0;
}
void Change::showEach() // will show the number of each amount
{
if (numTwenties > 0) //if the # of 20s is greater than 0
{
cout << "Twenties: " << numTwenties << endl; //output the number
}
if (numTens > 0) // if the # of 10s is greater than 0
{
cout << "Tens: " << numTens << endl; //output the number
}
if (numFives > 0) // if the # of 5s is greater than 0
{
cout << "Fives: " << numFives << endl; //output the number
}
if (numOnes > 0) // if the # of 1s is greater than 0
{
cout << "Ones: " << numOnes << endl; //output the number
}
if (numQuarters > 0) // if the number of .25s is greater than 0
{
cout << "Quarters: " << numQuarters << endl; // output the number
}
if (numDimes > 0) // if the # of .10s is greater than 0
{
cout << "Dimes: " << numDimes << endl; // output the number
}
if (numNickels > 0) // if the # of nickels is greater than 0
{
cout << "Nickels: " << numNickels << endl; // output the number
}
if (numPennies > 0) // if the number of pennies is greater than 0
{
cout << "Pennies: " << numPennies<< endl; // output the number
}
}
void Change::setEachToZero()
{
numTwenties = 0;
numTens = 0;
numFives = 0;
numOnes = 0;
numQuarters = 0;
numDimes = 0;
numNickels = 0;
numPennies = 0;
}
void Change::AmountToMakeChangeFor(double amt_p)
{
numTwenties = (amt_p / 20);
amt_p = (amt_p - (numTwenties * 20);
numTens = (amt_p / 10);
amt_p = (amt_p - (numTens * 10);
numFives = (amt_p / 5);
amt_p = (amt_p - (numFives * 5);
numOnes = (amt_p /1);
amt_p = (amt_p - (numOnes * 1);
numQuarters = (amt_p / .25);
amt_p = (amt_p - (numQuarters * .25);
numDimes = (amt_p / .10);
amt_p = (amt_p - (numDimes / .10);
numNickels = (amt_p / .05);
amt_p = (amt_p - (numNickels * .05);
numPennies = (amt_p / .01);
}