Elapsed Time

Can someone help me on using elapsed time, my code doesn't work. Please edit it for me.

int time=10;
if(t.elapsedTime()>time)
{
cout<<"You ran out of time!"<<endl;
return 0;
}
Please edit it for me

Please use code tags* and ask a question.

*
[code]//some code[/code]


It would also be helpful if you provided minimal code and an explanation what you are trying to do. Anyways is your elapsed time ==
1
2
start - finish
finish - start

*edit had the elapsed formula backwards should be end - start.
Last edited on
Thanks
Last edited on
*Can someone help me on using elapsed time, my code doesn't work. Please edit it for me.*

int time=10;//int that has amount of time I want to count
if(t.elapsedTime()>time)//if the time already passed is bigger than the time I want to count
{
cout<<"You ran out of time!"<<endl;//say you ran out of time
return 0;//end program
}
I didn't mean to annotate your lines. I meant a little more specific other than
my code doesn't work.


Also where is this elapsedTime coming from? SFML time?

A easy way (though probably not the best) would be something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <ctime>

int main()
{
    std::clock_t start = std::clock(); //http://www.cplusplus.com/reference/ctime/clock/

    for(int i = 0; i < 1e3; ++i)
    {
        std::cout << "Wasting time!" << std::endl;
    }

    std::clock_t end = std::clock();
    double elapsed = (end-start) / static_cast<double>(CLOCKS_PER_SEC); 

    std::cout << "Elapsed time(sec): " << elapsed << std::endl;
}

thanks a lot.
Topic archived. No new replies allowed.