Hi all... Can somebody explain to me why this code only works when I uncomment a specific line. It's not a crazy precision timer or anything just messing around atm, but don't understand the behavior.
#include <iostream>
#include <string>
#include <time.h> // clock_t, clock, CLOCKS_PER_SEC
unsigned int timer(){
clock_t t;
t = clock();
unsigned int curtime = 0;
while(CLOCKS_PER_SEC != 2000){
return curtime += t;
}
}
int main(){
std::string hello = "Wake up Neo...";
unsigned int pos = 0;
unsigned int milli = 0;
unsigned int hunthou = 0;
unsigned int tenthou = 0;
unsigned int thou = 0;
unsigned int hun = 0;
while(true){ // runs forever atm
if(timer() > milli){
milli += 1;
if(milli == 10){
milli = 0;
hunthou += 1;
if(hunthou == 10){
hunthou = 0;
tenthou += 1;
if(tenthou == 10){
tenthou = 0;
thou += 1;
if(thou == 10){
thou = 0;
hun += 1;
if(hun == 10){
hun = 0;
}
}
}
}
}
//if i uncomment the line below it works?????
//std::cout << hun << thou << tenthou << hunthou << milli << '\n';
}
if(hun == 3){
std::cout << "yes";
hun = 0;
thou = 0;
tenthou = 0;
hunthou = 0;
milli = 0;
}
}
return 0;
}