Skip to content
Sign UpLog In
Profile icon

로로

@kiroro
Repls
Community
kiroro
kiroro
shared a Post
4 years ago
Function about measuring time
we are making a game, and in order to prevent from addiction, we are trying to measure the time the user has used the game, and close the project afte
mwilki7
mwilki7
You could create a time start variable timet timestart; at the beginning of your program and get the current time and subtract it with when your program started. #include #include #include "unistd.h" #include "time.h" using namespace std; timet getTimePassed(timet start, time_t end) { return end - start; } int main() { timet timestart; timet timecurrent; time(&time_start); sleep(5); time(&time_current); cout << getTimePassed(timestart, timecurrent) << endl; } 4 years ago
ash15khng
ash15khng
You can do something like add 1 to a second variable every second, then if it hits a limit it will stop? I have no idea how to do that tho I don't know C. Hope this somehow helps?4 years ago