Oct 19, 2016 at 7:19pm UTC
so i need to have two times calculated into minutes and find the difference my code only ignores the hours and just does the minutes if someone could find my error here that would be great
#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;
}