1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#include "stdafx.h"
#include<iostream>
using std::cout;
using std::cin;
int timeDifference(int hoursTime1, int minutesTime1, int total_mins1, int total_mins2,
int hoursTime2, int minutesTime2, bool isPM, bool isAM);
int main()
{
int hoursTime1, hoursTime2;
int minutesTime1, minutesTime2;
char time1, time2;
bool isPM = 0, isAM = 0;
cout << "Please enter the time 1: (Example (hours minutes) ie. (4 45): ";
cin >> hoursTime1 >> minutesTime1;
cout << "Please indicate Time 1 whether it is AM or PM (enter A for AM; enter P for PM: ";
cin >> time1;
if (( time1 == 'p') || (time1 == 'P'))
{
isPM = 1;
}
else
cin >> time1;
if (( time1 == 'a') || (time1 == 'A'))
{
isAM = 1;
}
int total_mins1 = (hoursTime1 * 60) + (minutesTime1);
cout << "Total minutes of Time 1 is: " << total_mins1 << "\n";
cout << "Please enter the time 2: (Example 12 30) ";
cin >> hoursTime2 >> minutesTime2;
cout << "Please indicate whether it is AM or PM (enter A for AM; enter P for PM: ";
cin >> time2;
if (( time2 == 'p') || (time2 == 'P'))
{
isPM = 1;
}
else
cin >> time2;
if (( time2 == 'a') || (time2 == 'A'))
{
isAM = 1;
}
int total_mins2 = (hoursTime2 * 60) + (minutesTime2);
cout << "Total minutes of Time 2 is: " << total_mins2 << "\n";
cout << "The time difference is: ";
cout << timeDifference(hoursTime1, minutesTime1, total_mins1, total_mins2, hoursTime2, minutesTime2, isPM, isAM);
return 0;
}
int timeDifference(int hoursTime1, int minutesTime1, int total_mins1, int total_mins2,
int hoursTime2, int minutesTime2, bool isPM, bool isAM)
{
int difference;
difference = total_mins1 - total_mins2;
if(isPM)
{
if((hoursTime1 >= 1) && (hoursTime1 < 12)) //if hours time 1 is >= 1 and hours time 1 < 12 then hoursTime1 is 12
{
hoursTime1 += 12;
}
}
if(isAM)
{
(hoursTime2 == 12);
{
hoursTime1 += 12;
}
}
return difference;
}
|