I'm just starting to pick up some of the concepts in C++ and I was wondering if it was possible to write a program where we can get change from a given amount of money, and in that amount of the change, the program will know how many quarters, dimes, nickels, and pennies will be given, without using if and then statements, or statements, loops or any of the advance stuff. Just variable declaration and assignments with simple arithmetic operations. I've attempted for about a few hours now but I cant seem to get it. Thus, I was wondering if it wasn't possible without the advance stuff? When I tried it, say the change given is $3.28. I tried separating the input of the dollars from the change, and having it setted up as 3 dollars and .28 cents. It worked to an extent and I was able to get it to tell me that that was made up of 12 quarters, 2 dimes, and 8 pennies. However, I cant seem to integrate the nickels in there, or have the program just calculate how many of each just from $3.28 rather than 3 dollars and .28 cents individually. Therefore, I was wondering if it's possible at all to make this program with the current basic c++ commands that I currently know, which is just basic strings, assignments but nothing like loops and things beyond that.-Thank you
Yes, it is possible. Before you can write the program, though, you must work out the mathematics behind the solution. Sounds like you might be close. If I told you to make change for $0.67, how do you mentally solve the problem?
ok thanks, now I know that I still can pursue it then. Also, I get what you mean by making the change, but I just got to find the right algorithm. With .67 cents, I can do that with six dimes and seven pennies, or 2 quarters 2 nickels and and seven pennies. But hard part is if i choose to go with 2 quarters first, I'm trying to find out how to transfer the remaining value to the over coins, and make it as general as possible so that it will work for all amounts given by the user, but thanks again for letting me know that its possible. Guess its time to hit the papers..
Do you want to get only one solution (one way to make change), or all the possible solutions, because these are very different programs.
enlightenMe wrote:
But hard part is if i choose to go with 2 quarters first, I'm trying to find out how to transfer the remaining value to the over coins ...
How did you do that with dollars?
enlightMe wrote:
When I tried it, say the change given is $3.28. I tried separating the input of the dollars from the change, and having it setted up as 3 dollars and .28 cents.
I was able to get my program to work. I setted it up in a way that it gives the whole amount in quarters first and covert what is left into the other coins. Such as 4.00 will give it in all 16 quarters, or if it was 4.33 it turns that into 17 quarters 0 dimes, 1 nickel, and 3 pennies, so I'm guessing I was aiming for just one way to make the change, based on quarters. Thanks for the help and replies though to you and jsmith!