Computer Science Canada coin problem |
Author: | starlight [ Tue Mar 08, 2005 6:05 pm ] |
Post subject: | coin problem |
How can you make a programe that allows the user to enter the amount of money in cents. and the computer will calculate the smallest number of coins needed to obain this amount of money. available coin values are: $0.01 $0.10 $0.25 $1.00 $2.00 thanks in advance |
Author: | person [ Tue Mar 08, 2005 6:12 pm ] |
Post subject: | |
a lot of if statements is wat i would do[/code] |
Author: | cool dude [ Tue Mar 08, 2005 6:47 pm ] |
Post subject: | |
i love those kinda questions. everyone that starts off in turing has to do stuff like that and they have trouble with it. like "person" said use if statements and make constants which hold the value of something it's a lot easier. the assignment is probably due by now because it's like 15 lines or so, so i want bother posting the code. |
Author: | cool dude [ Tue Mar 08, 2005 7:02 pm ] | ||
Post subject: | |||
k i noticed that u just posted it so i'm guessing your not done. here is the start of the code and the rest is really simple so figure it out
i hope this helps |
Author: | cool dude [ Tue Mar 08, 2005 7:04 pm ] | ||
Post subject: | |||
sorry i messed one thing up so this one is the one thats almost done
|
Author: | Token [ Tue Mar 08, 2005 7:06 pm ] |
Post subject: | |
lol at first i thaught that he ment to use the least number of coins to make a certian ammount, for example $2.37 the least number of coins would be 1 toonie 1 quarter 1 dime and 2 pennies i'll post the code for this in a seccond just in case that was what you were refering to |
Author: | person [ Tue Mar 08, 2005 7:06 pm ] |
Post subject: | |
yes i am a n00b and u should learn to read because he asked for combinations not wat u gave him EDIT: i read it again and i realize im the one that needs to read (how ironic) |
Author: | cool dude [ Tue Mar 08, 2005 7:09 pm ] |
Post subject: | |
person wrote: yes i am a n00b and u should learn to read because he asked for combinations not wat u gave him
wat who called u a noob? u r a haker. if your saying i called u a noob their must be some misunderstanding. ![]() plus the second code i gave him works just like he wants it, but he just has to add a few if statements so all of the coins don't show up |
Author: | person [ Tue Mar 08, 2005 7:16 pm ] |
Post subject: | |
sorry im an idiot...i read it again...forgot to see the period....(really pissed off today becasue got 10% on French test)...sorry |
Author: | cool dude [ Tue Mar 08, 2005 7:21 pm ] |
Post subject: | |
thats okay, happy that was cleared up. sorry for the misunderstanding ![]() |
Author: | Token [ Tue Mar 08, 2005 7:40 pm ] | ||
Post subject: | |||
Here, what this does is the same thing that somone working a till would do, it works up in each size, starting with the largest, and when that size wont fit anymore it goes with a smaller size of coin, all that it does is adds up with the toonie and then when no more will fit it changes to loonies and counts up, and when they wont fit anymore it counts with quarters, and so on, so i think this is what 'Starlight' was refering to, hope it helps,
lol i originally forgot to post the code... oopsies ![]() |
Author: | starlight [ Tue Mar 08, 2005 7:41 pm ] |
Post subject: | |
sorry i didn't express this clearly enough. i want a combination of coins that use the least number of coins to make a certian amount . Just as "Token" said in the comment. |
Author: | starlight [ Tue Mar 08, 2005 7:58 pm ] |
Post subject: | |
thanks. Now I pretty much get how you make the programe. But one more question. what does "+=" mean in turing ? |
Author: | Token [ Tue Mar 08, 2005 8:01 pm ] |
Post subject: | |
It is an incrementing variable its the same as putting total := total + 5 so if the total was before 10 it is now 15 edit: hah beat ya to it Bacchus, look at how close the times were tho |
Author: | Bacchus [ Tue Mar 08, 2005 8:01 pm ] |
Post subject: | |
a+=b basically means a:=a+b , its just short form (you can also do -=), i think theres a tutorial that gives for shortcuts too |
Author: | starlight [ Tue Mar 08, 2005 8:12 pm ] |
Post subject: | |
thanks guys that really helps. ![]() ![]() |
Author: | ssr [ Tue Mar 08, 2005 8:51 pm ] |
Post subject: | |
hey I think I did this program before its actually pretty easy 1. see how many $1 if 0 then put 0 dollars 2. get the remainder adn see how many quarters 3. so on so on I will post the code after Im finished 8) |
Author: | ssr [ Tue Mar 08, 2005 9:20 pm ] | ||
Post subject: | |||
sorry took so long gotta do my hwk anyway not the best but works the principle is liek this no need for loop or anything 8) |
Author: | starlight [ Thu Mar 10, 2005 4:42 pm ] |
Post subject: | |
is there a way that used MOD instead of all the minus sign? in q := (price - t * 200 - l * 100) div 25 ? |
Author: | ssr [ Thu Mar 10, 2005 6:26 pm ] |
Post subject: | |
yes I guess so... 8) |
Author: | starlight [ Thu Mar 10, 2005 6:30 pm ] |
Post subject: | |
really? But i tried many different ways. but it always give me either a error message or the wrong answer. |
Author: | ssr [ Thu Mar 10, 2005 6:57 pm ] |
Post subject: | |
USing mod would be complicated and unclear, use div is teh best way ![]() |