新人请教程序错在哪,用户输入数据后,就没有输出了
题目要求:代码:
程序代码:
#include <stdio.h> #include <stdlib.h> int main(void) { #define DEPART_TIME_1 (8 * 60) #define DEPART_TIME_2 (9 * 60 + 43) #define DEPART_TIME_3 (11 * 60 + 19) #define DEPART_TIME_4 (12 * 60 + 47) #define DEPART_TIME_5 (14 * 60) #define DEPART_TIME_6 (15 * 60 + 45) #define DEPART_TIME_7 (19 * 60) #define DEPART_TIME_8 (21 * 60 + 45) int h, m, user_time, min; printf("Enter a 24-hour time(h:m): "); scanf("%d:%d", &h, &m); user_time = h * 60 + m; min = (abs(user_time - DEPART_TIME_1) < abs(user_time - DEPART_TIME_2)) ? abs(user_time - DEPART_TIME_1) : abs(user_time - DEPART_TIME_2); min = (min < abs(user_time - DEPART_TIME_3)) ? min : abs(user_time - DEPART_TIME_3); min = (min < abs(user_time - DEPART_TIME_4)) ? min : abs(user_time - DEPART_TIME_4); min = (min < abs(user_time - DEPART_TIME_5)) ? min : abs(user_time - DEPART_TIME_5); min = (min < abs(user_time - DEPART_TIME_6)) ? min : abs(user_time - DEPART_TIME_6); min = (min < abs(user_time - DEPART_TIME_7)) ? min : abs(user_time - DEPART_TIME_7); min = (min < abs(user_time - DEPART_TIME_8)) ? min : abs(user_time - DEPART_TIME_8); switch (user_time - min) { case DEPART_TIME_1: printf("Closest departure time is 8:00 a.m., arriving at 10:16 a.m."); break; case DEPART_TIME_2: printf("Closest departure time is 9:43 a.m., arriving at 11:52 a.m."); break; case DEPART_TIME_3: printf("Closest departure time is 11:19 a.m., arriving at 1:31 p.m."); break; case DEPART_TIME_4: printf("Closest departure time is 12:47 p.m., arriving at 3:00 p.m."); break; case DEPART_TIME_5: printf("Closest departure time is 2:00 p.m., arriving at 4:08 p.m."); break; case DEPART_TIME_6: printf("Closest departure time is 3:45 p.m., arriving at 5:55 p.m."); break; case DEPART_TIME_7: printf("Closest departure time is 7:00 p.m., arriving at 9:20 p.m."); break; case DEPART_TIME_8: printf("Closest departure time is 9:45 p.m., arriving at 11:58 p.m."); break; } return 0; }屏幕输出:
输入9:00后,就没有第二步输出了,请问哪个地方有问题?
[ 本帖最后由 tximist 于 2015-9-20 17:03 编辑 ]