So, I have to make the following program:
I input two "clocks", in format HH:MM, and I have to check the difference between them in minutes and output it. Then I have to check which time has bigger size, in minutes, and output which time is bigger or if they are equal.
So, I've done this:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
string a, b, c, d;
int a_min, b_min;
getline(cin, a, ':');
cin >> b;
getline(cin, c, ':');
cin >> d;
a_min = atoi(a.c_str()) * 60 + atoi(b.c_str());
b_min = atoi(c.c_str()) * 60 + atoi(d.c_str());
if (a_min > b_min){
cout << "Razlikata iznesuva " << a_min - b_min << " minuti" << endl;
cout << "Pogolemo e prvoto vreme" << endl;
}
else if (b_min > a_min){
cout << "Razlikata iznesuva " << b_min - a_min << " minuti" << endl;
cout << "Pogolemo e vtoroto vreme" << endl;
}
else if (a_min == b_min){
cout << "Vreminjata se isti" << endl;
}
return 0;
}
But when you input HH:MM, I have a ":" between the HH and MM, therefore I can't get the numbers simply, so I need help how to get hours and minutes and convert them (conversion should be easy I guess) or if there's alternative and better method for this?