View Single Post
  #10   Spotlight this post!  
Unread 15-12-2006, 19:48
neilsonster's Avatar
neilsonster neilsonster is offline
Registered User
AKA: Andrew Neilson
FRC #0772 (Sabre Bytes)
Team Role: College Student
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Waterloo, ON, Canada
Posts: 188
neilsonster is a name known to allneilsonster is a name known to allneilsonster is a name known to allneilsonster is a name known to allneilsonster is a name known to allneilsonster is a name known to all
Send a message via MSN to neilsonster
Re: Rounding numbers

Ohh I see. Actually, this line:

Code:
time_i = ((i * 262) / 10000);
performs integer division, since time_i is an integer (you declared it as one). If you had declared time_i as a float/double, then this would give you a floating point number.

So after that line above, time_i is assigned 0 until i > 38 (i*262/10000 = i*0.0262 < 1, but since we have an integer it truncates the decimal part and gives you 0). For 38 <= i <= 76, time_i will be assigned 1 (you will have 1.***, and the decimal part will be removed). For 77 <= i <= 152, time_i = 2, and so on.
__________________
Andrew Neilson - Team 772 Alumnus
University of Waterloo Computer Science, Class of 2010