#include #include void pause (void) { cout << "\nHit any key to continue...\n"; getch (); } int convert_to_total_minutes (int hours, int minutes) { return (hours * 60) + minutes; } int main () { int count = 0, new_time, last_time, gap, longest_gap = -1, hours, minutes; long gap_total = 0; for (;;) { cout << "Enter time in hours and minutes (99 99 to stop): "; cin >> hours >> minutes; if ((hours == 99) && (minutes == 99)) { break; } if ((hours < 0) || (hours > 23) || (minutes < 0) || (minutes > 59)) { cout << "** Time ignored - hours and/or minutes invalid." << endl; } else { new_time = convert_to_total_minutes (hours, minutes); if (count == 0) { // our very first time last_time = new_time; count++; } else if (new_time < last_time) { cout << "** Time ignored - not >= previous time **" << endl; } else { gap = new_time - last_time; gap_total += gap; if (gap > longest_gap) { longest_gap = gap; } last_time = new_time; count++; } } } if (count < 2) { cout << "Fewer than 2 times were entered - no gaps to analayze.\n"; } else { cout << count << " times were entered.\n" << "The longest gap is " << longest_gap << " minutes long.\n" << "The average gap length is " << gap_total / (count - 1.0) << " minutes.\n"; } pause (); return 0; }