Computer Science Canada Fixing Code |
Author: | Booya [ 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 |
Author: | McKenzie [ Wed Dec 14, 2005 10:04 pm ] | ||
Post 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.
|