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
|
#include <iostream>
#include <cmath>
using namespace std;
void readTime(int& hr, int& min, bool& isAM)
{char extra1, extra2, ampm;
cout << "Enter the Time:";
cin >> hr >> extra1 >> min >> ampm >> extra2;
if (ampm == 'a')
isAM = true;
else
isAM = false;
if ((hr=12) && (isAM=true))
hr=0;
}
int covtTime (int hourP,int minuteP,bool amP, int hourF, int minuteF, bool amF)
{int totalMP, totalMF, totalDiff;
if (amP = true)
totalMP = (hourP * 60) + minuteP;
else
totalMP = (hourP * 60) + minuteP + 720;
if (amF = true)
totalMF = (hourF * 60) + minuteF;
else
totalMF = (hourF * 60) + minuteF + 720;
totalDiff = totalMF - totalMP;
return totalDiff;
}
int main()
{
int hourP, minuteP, hourF, minuteF, totalDiff;
bool amP, amF;
readTime (hourP, minuteP, amP);
readTime (hourF, minuteF, amF);
totalDiff = covtTime (hourP, minuteP, amP, hourF, minuteF, amF);
cout << "The Time Difference is " << totalDiff << "minutes" << endl;
}
|