c++ - Counter keeps repeating please provide answer -


now, learning c programming, stumbled upon countdown code on 'codeproject.com' , decided run , analyse learn. however, output countdown repeats each number thousands of times before moving next. please need understanding why is. code shown below:

#include <stdio.h> #include <time.h>  int main() {       unsigned int x_hours = 0;         unsigned int x_minutes = 0;       unsigned int x_seconds = 0;       unsigned int x_milliseconds = 0;       unsigned int totaltime = 0, count_down_time_in_secs = 0, time_left=0;        clock_t x_starttime, x_counttime;       count_down_time_in_secs = 10; // 1 min 60        x_starttime = clock();       time_left = count_down_time_in_secs-x_seconds;  //update timer        while (time_left>0)       {         x_counttime = clock();         x_milliseconds = x_counttime-x_starttime;         x_seconds=(x_milliseconds/(clocks_per_sec))-(x_hours*60);         x_minutes=(x_milliseconds/(clocks_per_sec))/60;         x_hours=x_minutes/60;           time_left = count_down_time_in_secs-x_seconds;           printf("\nyou have %d seconds left", time_left, count_down_time_in_secs);       }        printf("\n\n\ntime's out\n\n\n");      return 0; } 

just add line print out x_milliseconds inside loop , become obvious happening. i.e. executing loop thousands of times second.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -