hello, i’m new to programming in i’m trying to solve this exercise in C, basically it’s the amount of passed hours between the start of a game and it’s end, if the game started at 16 and ended at 2 the result is a game with 10 hours(in different days) i know i can to it more manually, but i wanted to somehow use the <time.h> to learn how to use a header etc, can someone help me?, thank you all
You save the unix timestamp at the beginning of the game and the end of the game (or use the current one). With this timestamps you can use functions to calculate length etc. For example https://cplusplus.com/reference/ctime/difftime/ You then can convert those into a better format. More info here https://cplusplus.com/reference/ctime/
Also chatgpt could help in those cases, if you don’t want to wait for a answer on here :P
I think the is the most accurate solution,
clock()
as suggested by another answer may overflow, but this only suffers from potential precision problems with double, but you’d have to wait for an incredibly long time for this to become significant.