Ok, I am fairly new to C++ programming and I need to make a program that asks the user to cout<<"Enter an of change (in cents): "; and then the program will calculate the amount of change in quarters, dimes, nickels, and pennies. I can't even figure out a way to start this program otherwise I would have posted some type of progress on it. Should I have three different void functions that I call in the int main? If anyone can help me get through this I would really appreciate it.
I used the thread you posted as some type of a guide to get this started but I am having troubles in the computations. I am getting weird numbers as much answers and I need the extras to roll over.. i.e. 5 pennies would be 1 nickel and 2 nickels would roll over to a dime. I may need to use the modulous operator?
You are making a common beginner mistake: When you divide integers, an integer will be returned and any floating point values will be clipped. I suggest you use floating point datatypes to handle currencies. I've also made a few more changes to your code:
Using constants for fixed values makes your code usually more readable than using "magic numbers" (numbers in the code that may not mean much to someone not familiar with the program).
Also, please note that we try to discourage the use of system() because it holds safety risks. For alternative methods of preventing the console closing down, please see: http://www.cplusplus.com/forum/beginner/1988/
unsignedint numQuarters = amountInCents / QUARTER_AMT; //here's how many whole quarters I can take out
amountInCents -= (numQuarters * QUARTER_AMT); //if I take out that many quarters, here's what I'm left with to work on
unsignedint numDimes = amountInCents / DIME_AMT;
amountInCents -= (numDimes * DIME_AMT);
unsignedint numNickels = amountInCents / NICKEL_AMT;
amountInCents -= (numNickels * NICKEL_AMT);
unsignedint numPennies = amountInCents;
amountInCents is what you start with from the user. As you go along, decrement this total by however much change you've translated into coin amounts.