/***************************************************
Conversion from 12-hour clock to 24 hour clock
Write a program that reads in time in 12-hour
format (e.g. 10:25PM), and writes it out in 24-hour
format (e.g. 22:25).
***************************************************/
#include <iostream>
#include <string>
using namespace std;
int main()
{
// Read time in 12-hour format
int h, m;
char c;
string s;
cout << "Enter the time as h:m AM/PM (e.g. 10:25PM): ";
cin >> h >> c >> m >> s;
// Write "hour" part time in 24-hour format
if ((s == "PM") && (h != 12))
{
cout << h + 12;
}
else
{
cout << h;
}
// Write "minute" part (might need to add leading zero)
if (m < 10)
{
cout << ":0" << m << endl;;
}
else
{
cout << m << endl;
}
return 0;
}