/***************************************************
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 "si204.h"

int main() {
  // Read time in 12-hour format
  fputs("Enter the time as h:m AM/PM (e.g. 10:25PM) ", stdout);
  int h = readnum(stdin);
  readchar(stdin); // ignore the colon
  int m = readnum(stdin);
  cstring ampm;
  readstring(ampm, stdin);

  // Get the hour in 24-hour format
  if (strcmp(ampm, "PM") == 0) {
    h = h + 12;
  }

  // Write the hour with 2 digits
  if (h < 10) {
    fputc('0', stdout);
  }
  writenum(h, stdout);

  fputc(':', stdout);

  // Write the minute with 2 digits
  if (m < 10) {
    fputc('0', stdout);
  }
  writenum(m, stdout);

  fputc('\n', stdout);

  return 0;
}