i have to create c++ program.
The program requires the time format hh : mm : ss and check the correctness of the input , eliminating the appropriate report , such as:
23:09:03 - correctly ,
2: 2: 2 - wrong format ,
12:02:94 - wrong time
05/14/35 - wrong format ,
qw2 : we34 - wrong format .
First check is the number is not another character
then check if : is exist
then check is the number consist of 2 number
last check is the number is higher that highest value or the opposite
Given 23:09:03 is good, you can see that:
- you need to check the type of elem 0-7 are the type expected (inc. that there are just 8 elems.)
- then check each digit pair is in range.
Or exploit the fact that the ':' turns up every 3 chars?
Andy
PS Here I would be tempted to code my own conversion function that use stoi or whatever (as it's always 2 chars to a value)
thanks everyone for help and ideas i just added one more function that checks if there is 8 elements and since i had everything else already defined i didn't go any deeper than that :)