Look into the <chrono>
standard C++11 header. See also this question.
You would convert the "04:25"
string (read a lot more about std::string, which has a quite rich API) to some time (actually, a time_point
, or a clock
, or a duration
) and work on that time.
On POSIX systems (notably Linux) you might instead use (even with an old C++ or in plain C) the time related functions (read time(7)...) such as strftime(3) and strptime(3) (see also localtime(3) & timelocal(3)...)
Alternatively, you might simply compute minutes, with the insight that "04:45"
should be parsed as 04
(in decimal, use std::stoi to convert, or even the strtol function of C or its sscanf) * 60 + 45
and "07:10"
is 7*60 +10
that is 430; to make the reverse transformation consider 430/60
(giving 7) and 430%60
giving 10.
Don't forget to enable all warnings & debug info when compiling (e.g. compile with g++ -Wall -Wextra -g
if using GCC...) and use the debugger (e.g.gdb
) to understand the behavior of your program (e.g. by running it step by step and querying its state).
Your question is extremely basic (and shows some difficulty with elementary programming and math, unrelated to C++). I strongly recommend spending days in reading some basic math textbook (high-school level, explaining quotient and modulus and bases & radixes), then SICP (an excellent introduction to programming, not using C++), then Programming using C++. Don't forget to read some reference documentation about C++.