#include #include #include long pickrange(long low, long high, long decs); long pickampm(); long convertmonth(long month,long year); void display_time(long number,char timername[]); int main () { long time1,time2; long formdate; long second, minute, hour, day, month, year; char timername[32]; time1 = time(NULL); clrscr(); printf("\n Select Time: 01:00:00 AM\b\b\b\b\b\b\b\b\b\b\b"); hour = pickrange(1,12,2); printf(":"); minute = pickrange(0,59,2); printf(":"); second = pickrange(0,59,2); printf(" "); hour += pickampm(); printf("\n Select Date: 01/01/2006\b\b\b\b\b\b\b\b\b\b"); month = pickrange(1,12,2); printf("/"); day = pickrange(1,31,2); printf("/"); year = pickrange(2006,2100,4); month = convertmonth(month,year); printf("\n Select Name: "); scanf("%s", timername); formdate = (year - 1970) * 60 * 60 * 24 * 365; formdate += (month + day -1) * 60 * 60 * 24; if ( hour == 24 ) hour = 0; formdate += (hour - 0) * 60 * 60; formdate += (minute - 0) * 60; formdate += (second - 0); formdate += 14400; clrscr(); while ( formdate > time1 ) { time1 = time(NULL); if ( time1 > time2 ) { time2 = time1; display_time(formdate-time2, timername); } } printf("\n%s\n", timername); getch(); return 0; } long pickrange(long low, long high, long decs) { long number = low; char input = '?'; if ( high < 100 ) printf("0"); printf("%ld", number ); while ( input != 13 ) { input = getch(); if ( input == 0 ) { switch ( getch() ) { case 72: if ( number < high ) number++; break; case 80: if ( number > low ) number--; break; } } if ( number > 1000 ) printf("\b\b\b\b%ld", number); else { printf("\b\b"); if ( number < 10 ) printf("0"); printf("%ld",number); } } return number; } long pickampm() { long ampm = 0; char input = '?'; printf("AM"); while ( input != 13 ) { input = getch(); if ( input == 0 ) { switch ( getch() ) { case 72: if ( !ampm ) ampm = 12; break; case 80: if ( ampm ) ampm = 0; break; } } if ( ampm == 0 ) printf("\b\bAM"); else printf("\b\bPM"); } return ampm; } long convertmonth(long month,long year) { /* ! J F M A M J J A S O N D */ long array[13] = { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; month = array[month]; if (year % 4 == 0 && month >= 59 ) { month++; } month += (year - 1967)/4; return month; } void display_time(long number, char name[]) { printf("%c%s: ", 13,name); if ( number/3600 > 0 ) { if ( number/3600 < 10 ) printf("0"); printf("%d:", number/3600); } number = number % 3600; if ( number/60 > 0 ) { if ( number/60 < 10 ) printf("0"); printf("%d:", number/60); } number = number % 60; if ( number < 10 ) printf("0"); printf("%d ", number); }