### Time traking

Hi everyone!
I have a program that requires me to track the time between the last object created to know when to create another one.

The program is about a game that moves a dropper or square around the window. This square on a certain random time must drop a colored square (called box from another class) that will fall down. Then I need to count the time to check when to drop the next one, and so on

The thing is that I don't know how to count the seconds in a program!!
If someone can help me I will really appreciate it.

This is what I tried.

dropper::dropper()
{

int currentXp= getx();
int currentYp= gety();
srand( static_cast<int>( time( NULL ) ) );
currentYp=rand()%SCREEN_H;
currentXp=rand()%SCREEN_W;

upleftC.SetXY(currentXp,currentYp);
length=20;
width=20;
rgb colordrop(1.0,1.0,0.0);

color=colordrop;
//setcolor(color);

velocity.setx(rand()%100+200);
velocity.sety(rand()%100+200);

totalsec=time(0);
currentsec=totalsec%60;
}

THE TIME DOES NOT INCREASE.
 ``123456789101112131415`` `````` time_start_ = time(NULL); double elapsed_time = static_cast(time(NULL)-time_start_); if(elapsed_time < 60) { int P = (int) floor(log10(elapsed_time))+4; cout << "Total elapsed time: " << std::setprecision(P) << fmax(1,elapsed_time) << (elapsed_time<=1?" second":" seconds") << endl; } else if((elapsed_time/60.0) < 60) { elapsed_time /= 60.0; int P = (int) floor(log10(elapsed_time))+4; cout << "Total elapsed time: " << std::setprecision(P) << elapsed_time << (elapsed_time==1?" minute":" minutes") << endl; } else { elapsed_time /= 3600.0; int P = (int) floor(log10(elapsed_time))+4; cout << "Total elapsed time: " << std::setprecision(P) << elapsed_time << (elapsed_time==1?" hour":" hours") << endl; } ``````

Some code from one of my projects :)
Topic archived. No new replies allowed.