C++/difference between times given in the format hh:mm AM/PM
how to find the difference between two times given in the format hh:mm AM/PM, and the output should be in the format x hrs and y min.
There is a function in the C++ time class that allows you to find the difference between times. First of all I do not understand what AM and PM has to do with a difference in time. You will have to decipher that yourself. The function takes two "raw" times and returns the difference as a double in seconds. I looked for a function that would return the exact format you asked for, but I did not find one that gave the results using double input.
/* difftime example */
int main ()
char szInput ;
printf ("Please, enter your name: ");
dif = difftime (end,start);
printf ( "%d:%d" , dif / 3600 , ( dif % 3600 ) / 60 ) ;
There is a time class function that puts time in the format you want (strftime), but it does not take double and it does not take the difference of times: http://www.cplusplus.com/reference/clibrary/ctime/strftime.html