Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 coin problem
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
starlight




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
person




PostPosted: Tue Mar 08, 2005 6:12 pm   Post subject: (No subject)

a lot of if statements is wat i would do[/code]
cool dude




PostPosted: Tue Mar 08, 2005 6:47 pm   Post subject: (No 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.
cool dude




PostPosted: Tue Mar 08, 2005 7:02 pm   Post subject: (No 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

code:

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




PostPosted: Tue Mar 08, 2005 7:04 pm   Post subject: (No subject)

sorry i messed one thing up so this one is the one thats almost done

code:

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




PostPosted: Tue Mar 08, 2005 7:06 pm   Post subject: (No 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
person




PostPosted: Tue Mar 08, 2005 7:06 pm   Post subject: (No 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)
cool dude




PostPosted: Tue Mar 08, 2005 7:09 pm   Post subject: (No 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. Shocked

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
Sponsor
Sponsor
Sponsor
sponsor
person




PostPosted: Tue Mar 08, 2005 7:16 pm   Post subject: (No 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
cool dude




PostPosted: Tue Mar 08, 2005 7:21 pm   Post subject: (No subject)

thats okay, happy that was cleared up. sorry for the misunderstanding Crying or Very sad
Token




PostPosted: Tue Mar 08, 2005 7:40 pm   Post subject: (No 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,

code:
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 Laughing
starlight




PostPosted: Tue Mar 08, 2005 7:41 pm   Post subject: (No 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.
starlight




PostPosted: Tue Mar 08, 2005 7:58 pm   Post subject: (No subject)

thanks. Now I pretty much get how you make the programe. But one more question. what does "+=" mean in turing ?
Token




PostPosted: Tue Mar 08, 2005 8:01 pm   Post subject: (No 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
Bacchus




PostPosted: Tue Mar 08, 2005 8:01 pm   Post subject: (No 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 22 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: