Thank you so much. God, how could I so stupid! Who is this? oh ya, LEF, Thank You so much LEF.
regards Yuda --- In [email protected], Lars Finsen <[EMAIL PROTECTED]> wrote: > > > Den 5. feb. 2007 kl. 10.31 skrev Yuda: > > > I have done my "time calculator" code for my assignment. This code > > calculates time to find out the total time after we give input. This > > code works, but for several input, it doesnt show accuracy. For > > example, when i input 545(means 5 hours and 45 minutes)+545(5 hours > > and 45 minutes), its output was = 1129(11 hours and 29 minutes). It > > supposed to be 1130(11 hours and 30minutes). anyone know what is wrong > > with this code? plz give understandable explanation!! > > When you convert your input to float, you risk rounding errors. There > is no need to convert to float here. You can split your input into > hours and minutes by first integer dividing it by 100, giving you the > hours, and then subtracting the hours multiplied by 100 from the > input, giving you the minutes. > > > > if(minute>=60 && minute<120) > > Also I think these tests are overdoing it. You will never get more > than 118 minutes with the kind of input you have. So the first test > (before the &&) should be enough. > > LEF >
