
-----------------------------------
starlight
Tue Mar 08, 2005 6:05 pm

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

-----------------------------------
person
Tue Mar 08, 2005 6:12 pm


-----------------------------------
a lot of if statements is wat i would do[/code]

-----------------------------------
cool dude
Tue Mar 08, 2005 6:47 pm


-----------------------------------
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.

-----------------------------------
cool dude
Tue Mar 08, 2005 7:02 pm


-----------------------------------
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


var money : real
var sum, sum1, sum2, sum3, sum4 : real
var total : real
put "please enter amount of money"
get money
sum:=money/2.00
sum1:=sum/1.00
sum2:=sum1/0.25
sum3:=sum2/0.10
sum4:=sum3/0.01
total := sum + sum1 + sum2 + sum3 +sum4

put "toonies ",sum
put "loonies ",sum1
put "quarters ",sum2
put "dimes ",sum3
put "pennies ",sum4


i hope this helps

-----------------------------------
cool dude
Tue Mar 08, 2005 7:04 pm


-----------------------------------
sorry i messed one thing up so this one is the one thats almost done


var money : real
var sum, sum1, sum2, sum3, sum4 : real
var total : real
put "please enter amount of money"
get money
sum:=money/2.00
sum1:=money/1.00
sum2:=money/0.25
sum3:=money/0.10
sum4:=money/0.01
total := sum + sum1 + sum2 + sum3 +sum4

put "toonies ",sum
put "loonies ",sum1
put "quarters ",sum2
put "dimes ",sum3
put "pennies ",sum4


-----------------------------------
Token
Tue Mar 08, 2005 7:06 pm


-----------------------------------
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

-----------------------------------
person
Tue Mar 08, 2005 7:06 pm


-----------------------------------
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)

-----------------------------------
cool dude
Tue Mar 08, 2005 7:09 pm


-----------------------------------
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.  :shock:

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

-----------------------------------
person
Tue Mar 08, 2005 7:16 pm


-----------------------------------
sorry im an idiot...i read it again...forgot to see the period....(really pissed off today becasue got 10% on French test)...sorry

-----------------------------------
cool dude
Tue Mar 08, 2005 7:21 pm


-----------------------------------
thats okay, happy that was cleared up. sorry for the misunderstanding :cry:

-----------------------------------
Token
Tue Mar 08, 2005 7:40 pm


-----------------------------------
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,

var total, current, penny : real
var toonie, loonie, quarter, dime, nickel : int

put "Enter the total: " ..
get total


toonie := 0
loop
    exit when (toonie + 1) * 2 > total
    toonie += 1
end loop

current := toonie * 2

loonie := 0
loop
    exit when loonie + 1 + current > total
    loonie += 1
end loop

current += loonie

quarter := 0
loop
    exit when ((quarter + 1) * .25) + current > total
    quarter += 1
end loop


current += quarter * .25

dime := 0
loop
    exit when ((dime + 1) * .10) + current > total
    dime += 1
end loop

current += dime * .10

nickel := 0

loop
    exit when ((nickel + 1) * .05) + current > total
    dime += 1
end loop

current += nickel * .05


penny := (total - current) * 100


put toonie, " Toonies"
put loonie, " Loonies"
put quarter, " Quarters"
put dime, " Dimes"
put nickel, " Nickels"
put penny, " Pennies"


lol i originally forgot to post the code... oopsies  :lol:

-----------------------------------
starlight
Tue Mar 08, 2005 7:41 pm


-----------------------------------
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.

-----------------------------------
starlight
Tue Mar 08, 2005 7:58 pm


-----------------------------------
thanks. Now I pretty much get how you make the programe. But one more question. what does "+=" mean in  turing ?

-----------------------------------
Token
Tue Mar 08, 2005 8:01 pm


-----------------------------------
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

-----------------------------------
Bacchus
Tue Mar 08, 2005 8:01 pm


-----------------------------------
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

-----------------------------------
starlight
Tue Mar 08, 2005 8:12 pm


-----------------------------------
thanks guys that really helps.  :oops:  :D

-----------------------------------
ssr
Tue Mar 08, 2005 8:51 pm


-----------------------------------
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)

-----------------------------------
ssr
Tue Mar 08, 2005 9:20 pm


-----------------------------------
var price : real
var t, l, q, d, n, p : real
put "Enter a price."
get price
price := price * 100
t := price div 200
l := (price - t * 200) div 100
q := (price - t * 200 - l * 100) div 25
d := (price - t * 200 - l * 100 - q * 25) div 10
n := (price - t * 200 - l * 100 - q * 25 - d * 10) div 5
p := price - t * 200 - l * 100 - q * 25 - d * 10 - n * 5
cls
put price / 100, " dollars needs ", t, " of $2,", l, " of $1,", q, " of $0.25,", d, " of $0.10,", n, " of $0.05,", p, " of $0.01."

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)

-----------------------------------
starlight
Thu Mar 10, 2005 4:42 pm


-----------------------------------
is there a way that used MOD instead of all the minus sign? in 
q := (price - t * 200 - l * 100) div 25 ?

-----------------------------------
ssr
Thu Mar 10, 2005 6:26 pm


-----------------------------------
yes I guess so... 8)

-----------------------------------
starlight
Thu Mar 10, 2005 6:30 pm


-----------------------------------
really? But i tried many different ways. but it always give me either a error message or the wrong answer.

-----------------------------------
ssr
Thu Mar 10, 2005 6:57 pm


-----------------------------------
USing mod would be complicated and unclear, use div is teh best way  :D
