#include<stdio.h>
int main(void)
{
int h1=8,m1=0,h2=9,m2=43,h3=11,m3=19,h4=12,m4=47,h5=14,m5=0,h6=15,m6=45,h7=19,m7=0,h8=21,m8=45,h,m,conv;
printf("Enter a 24-hour time: ");
scanf("%d:%d",&h,&m);
conv=h*60+m;
if(conv<h1*60+m1)
printf("Closest departure time is 8:00 a.m., arriving at 10:16 a.m.");
else if(conv<h2*60+m2)
{
if(conv-(h1*60+m1)<h2*60+m2-conv)
printf("Closest departure time is 8:00 a.m., arriving at 10:16 a.m.");
else
printf("Closest departure time is 9:43 a.m., arriving at 11:52 a.m.");
}
else if(conv<h3*60+m3)
{
if(conv-(h2*60+m2)<h3*60+m3-conv)
printf("Closest departure time is 9:43 a.m., arriving at 11:52 a.m.");
else
printf("Closest departure time is 11:19 a.m., arriving at 1:31 p.m.");
}
else if(conv<h4*60+m4)
{
if(conv-(h3*60+m3)<h4*60+m4-conv)
printf("Closest departure time is 11:19 a.m., arriving at 1:31 p.m.");
else
printf("Closest departure time is 12:47 p.m., arriving at 3:00 p.m.");
}
else if(conv<h5*60+m5)
{
if(conv-(h4*60+m4)<h5*60+m5-conv)
printf("Closest departure time is 12:47 p.m., arriving at 3:00 p.m.");
else
printf("Closest departure time is 2:00 p.m., arriving at 4:08 p.m.");
}
else if(conv<h6*60+m6)
{
if(conv-(h5*60+m5)<h6*60+m6-conv)
printf("Closest departure time is 2:00 p.m., arriving at 4:08 p.m.");
else
printf("Closest departure time is 3:45 p.m., arriving at 5:55 p.m.");
}
else if(conv<h7*60+m7)
{
if(conv-(h6*60+m6)<h7*60+m7-conv)
printf("Closest departure time is 3:45 p.m., arriving at 5:55 p.m.");
else
printf("Closest departure time is 7:00 p.m., arriving at 9:20 p.m.");
}
else if(conv<h8*60+m8)
{
if(conv-(h7*60+m7)<h8*60+m8-conv)
printf("Closest departure time is 7:00 p.m., arriving at 9:20 p.m.");
else
printf("Closest departure time is 9:45 p.m., arriving at 11:58 p.m.");
}
else printf("Closest departure time is 9:45 p.m., arriving at 11:58 p.m.");
return 0;
}
No comments:
Post a Comment