Guest_imported
New member
- Jan 1, 1970
- 0
Hi guys!
Ok, what Im trying to do is convert an input of time in hh:mm:ss to total seconds and vice versa. I have quite easily converted user input seconds to hh:mm:ss form (eg. 4356 s = 01:12:36)
Now im having trouble converting from hh:mm:ss to total seconds. The problem is I have to account for different inputs. eg. input 55 = 55 seconds or
input 22:55 = 1375 seconds or
input 1:22:55 = 4975 seconds.
the input can include none, one or two colons... Ive been trying to use cin.get(char c) while (c != ':') .... and ive tried using a counter to count the colons then
if (count == 2){...}
else if (count == 1) {...}
else if (count == 0) {...}
etc. But im still having trouble.
Can anyone possibly help a poor sap like me with any possible suggestions?? THnx
Ok, what Im trying to do is convert an input of time in hh:mm:ss to total seconds and vice versa. I have quite easily converted user input seconds to hh:mm:ss form (eg. 4356 s = 01:12:36)
Now im having trouble converting from hh:mm:ss to total seconds. The problem is I have to account for different inputs. eg. input 55 = 55 seconds or
input 22:55 = 1375 seconds or
input 1:22:55 = 4975 seconds.
the input can include none, one or two colons... Ive been trying to use cin.get(char c) while (c != ':') .... and ive tried using a counter to count the colons then
if (count == 2){...}
else if (count == 1) {...}
else if (count == 0) {...}
etc. But im still having trouble.
Can anyone possibly help a poor sap like me with any possible suggestions?? THnx