Hello guys. In my computer programming class I need to make a program that can compute the pocket change of any number specified by the user. So for example if I were to input 1.30 in the program it should output something like |
|
Hello guys. In my computer programming class I need to make a program that can compute the pocket change of any number specified by the user. So for example if I were to input 1.30 in the program it should output something like |
|
Last edited by Daredevilpwn; 09-27-2012 at 03:39 AM.
Well, I don't know anything about Java in particular (my class is using C++), but as far as general logic, I would start by converting the decimal amount to cents, then divide by the value of a quarter and round that figure down to an integer. That integer becomes your number of quarters, and you then subtract that number times 25 form the total. Repeat for each coin until the remaining amount is 0. There, I did your homework. |
|
Thanks, I understand now. Good luck with your c++ class |
|
Last edited by Daredevilpwn; 09-27-2012 at 04:09 AM.
Thanks, good luck with your java class! And, I say that (he says that) because it is in many ways open to interpretation, depending on how you the programmer want to do something - for example, there is not one correct way to implement the outline I gave above. It's all about creative problem solving, a very fun sort of puzzle. |
|
From what I know of javascript, I would create an object called "Quarter," "Dime," etc. Assign a value to each object (0.25, 0.10...) then create an ask box for each object, where the user inputs the number value of how many coins they have of each. "How many quarters do you have?" "How many dimes do you have?" |
|
What is the difference between javascript and java? I thing I've heard that it's a different scripting language, but that sound illogical, why not rename it completely then? How could you notice it was javascript and not java? Java = huge piece of code that make up a program/app/whatever? |
|
The simplest algorithm would divide 1.30 by .25, output the amount to be the quarters, divide the remainder by .10, output the remainder to be number of dimes, and so on. |
|
I assume this is only meant to support the standard american change (quarters, dimes, nickels and pennies). Then, it's super easy. |
|
Bookmarks