/* TMA02 q3a */ //Author: Chan Chi Ming(93504843), date: 15/01/2001 //This program is used to write out the 12-hour representation //of a 24-hour representation entered. #include <condefs.h> #pragma hdrstop #include <stdio.h> //--------------------------------------------------------------------------- #pragma argsused int main(int argc, char **argv) { int hour; int minute; bool morning = true; printf("Enter the time in 24-hour format (hh mm): "); scanf("%d", &hour); scanf("%d", &minute); if ((hour < 24)&&(minute < 60)) /*test the input is valid or not*/ { if (hour > 11) /*check whether the input hour is am or pm*/ { hour = hour - 12; morning = false; } if (minute > 10) printf("The time in 12-hour format is %2d:%2d", hour, minute); else printf("The time in 12-hour format is %2d:0%d", hour, minute); if (morning == true) { printf("AM"); } else { printf("PM"); } } else { printf("Error. Invalid input."); } getchar(); getchar(); return 0; }