Your time machine is capable of going forward in time up to 24 hours. The machine is configured to jump ahead in minutes. To enter the proper number of minutes into your machine, you would like a program that can take a start time (in hours, minutes,n and a Boolean indicating AM or PM) and a future time (in hours, minutes,n and a Boolean indicating AM or PM) and calculate the difference in minutes between the start and future time.

...

Apparently my program is returning wrong values. Can anyone isolate where the problem is occurring?

#include <iostream> using namespace std; int computeDifference(int hours1, int mins1, int hours2, int mins2, bool isPM1, bool isPM2); //calculates the time difference between the starting and ending time in minutes int main() { int hours1, mins1, hours2, mins2; bool isPM1 = 0, isPM2 = 0; char time1, time2; cout << "Please enter the starting hour: \n"; cin >> hours1; cout << "Please enter the starting minute: \n"; cin >> mins1; cout << "Please indicate whether it is AM or PM (enter A for AM; enter P for PM) \n"; cin >> time1; if ((time1 == 'p') || (time1 == 'P')) { isPM1 = 1; } cout << "Please enter the hour you would like to travel to: \n"; cin >> hours2; cout << "Please enter the minute of the hour you would like to travel to: \n"; cin >> mins2; cout << "Please indicate whether it is AM or PM (enter A for AM; enter P for PM) \n"; cin >> time2; if ((time2 == 'p') || (time2 == 'P')) { isPM2 = 1; } cout << "The time difference is: "; cout << computeDifference(hours1, mins1, hours2, mins2, isPM1, isPM2); if (computeDifference(hours1, mins1, hours2, mins2, isPM1, isPM2) == 1) cout << " minute.\n"; else cout << " minutes.\n"; system("PAUSE"); return 0; } int computeDifference(int hours1, int mins1, int hours2, int mins2, bool isPM1, bool isPM2) { int difference, total_mins1, total_mins2; if (isPM1) { if ((hours1 >= 1) && (hours1 < 12)) { hours1 += 12; } } if (isPM2) { if (hours2 >= 1 && hours2 < 12) { hours2 += 12; } } total_mins1 = (hours1 * 60) + mins1; total_mins2 = (hours2 * 60) + mins2; if ((hours1 >= hours2) || ((hours1 == hours2) && (mins1 > mins2))) { total_mins2 += 1440; } difference = total_mins2 - total_mins1; if (difference > 1440) { difference -= 1440; } return difference; }