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

Username:   Password: 
 RegisterRegister   
 Fixing Code
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Booya




PostPosted: Wed Dec 14, 2005 9:37 pm   Post subject: Fixing Code

Hey can anyone help figure out whats wrong with this code???????? It works except the cents!!!!!!!!!! 0,25, 0,10, etc

var dollar_value : real
var num100, num50, num20, num10, num5, num2, num1 : real
var num025, num010, num005, num001 : real


color (green)
put "Enter a dollar amount : $" ..
color (blue)
get dollar_value


num100 := floor (dollar_value / 100)
num50 := floor (dollar_value rem 100 / 50)
num20 := floor (dollar_value rem 50 / 20)
num10 := floor (dollar_value rem 20 / 10)
num5 := floor (dollar_value rem 10 / 5)
num2 := floor (dollar_value rem 5 / 2)
num1 := floor (dollar_value rem 2 / 1)
num025 := floor (dollar_value rem 1 / 0.25)
num010 := floor (dollar_value rem 0.50 / 0.10)
num005 := floor (dollar_value rem 0.25 / 0.05)
num001 := floor (dollar_value rem 0.10 / 0.01)


put num100
put num50
put num20
put num10
put num5
put num2
put num1
put num025
put num010
put num005
put num001
Sponsor
Sponsor
Sponsor
sponsor
McKenzie




PostPosted: Wed Dec 14, 2005 10:04 pm   Post subject: (No subject)

Hey cool error. My best bet is that internally you are getting 1.99999999 then flooring it and getting one. I've reproduced the error with simple numbers. If you follow the logic Turing is saying that floor(2) -> 1. I would suggest you simply look at the third line.
code:

put 12.12 rem .1 / .01              % 2
put floor(12.12 rem .1 / .01)       % 1
put 12.12*100 rem 10                % 2
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 1  [ 2 Posts ]
Jump to:   


Style:  
Search: