View Single Post
  #12   Spotlight this post!  
Unread 15-12-2006, 23:23
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Rounding numbers

Quote:
Originally Posted by teh_pwnerer795 View Post
Code:
int i = 1;
static int time_i;

i=i+1; // This will increment 'i' by the value 1 every loop
time_i = ((i * 262) / 10000);
I believe you have declared the wrong variable as static. The way it stands now, i will be set to 1 then incremented to 2 each time through the loop, and time_i will always be computed as 0. If you change it to say
Code:
static int i = 1;
int time_i;
instead, i will remember its value between loops and be incremented as desired, and time_i will do as neilsonster said...

...at least until 125 loops have occurred, after a bit more than 3.25 seconds, after which time (i * 262) will overflow and you'll start getting negative results.