Advice in C Programming Modern Approach 2nd Edition -


i'm self-learning c using book call 'c programming modern approach 2nd edition' please assist question, it's question on "if-else, switch" chapter. chapter 5 - if else, switch, programming projects qn 8

the following table shows daily flights 1 city another.

departure time          arrival time 8:00 a.m.                10:!6 a.m. 9.43 a.m.                11:52 a.m. 11:19 a.m.                1:31 p.m. 12:47 p.m.                3:00 p.m. 2:00 p.m.                 4:08 p.m. 3:45 p.m.                 5:55 p.m. 7:00 p.m.                 9:20 p.m. 9:45 p.m.                11:58 p.m. 

write program ask user enter time(expressed in hours , minutes, using 24-hour clock). program displays departure , arrival times flight departure time closest entered user:

**enter 24-hour time: 13:15 closest departure time 12:47 p.m., arriving @ 3:00 p.m.** 

hint : convert input time expressed minutes since midnight, , compare departure times, expressed in minutes since midnight, example, 13:15 13 x 60 + 15 = 795 minutes since midnight, closer 14:47. (767 minutes since midnight) of other departure times.*

i can't seem ideal code question. i've no idea how can "compare" time "closer" time using if-else or switch. neither have other type of answers function or array. please give guidance i've been trying solve long time.

please provide code can @ how it. thank you.

just detailed: how compare closer departure time.

for time before first departure time, or after last departure time, should easy beginner such you. other, need calculate middle between departure times, , compare entered time find closest departure time.

for example, lets take 2 departure times 11:19 a.m. , 12:47 p.m. halfway between times 12:03 p.m. if entered time before (less than) 12:03 pm, closest departure time 11:19 am, , if entered time after (larger than) 12:03 pm 12:47 pm departure time closer.

my suggestion make structure, containing departure , arrival times, , make array of them specified departure , arrival times. make array, containing information middle times. like

struct times {     char *departure;     char *arrival; } times[] = {     { "8:00", "10:16" },     { "9:43", "11:52" },     .     .     . };  char *inbetween_times[] = {      "8:51",  // time between first , second departure     "10:31",  // time between second , third departure     .     .     . }; 

with above system, , above data, times before 8:51 closest first departure, times between 8:51 , 10:31 closest second, end on.

i don't know it's best way, , it's isn't way, it's way popped head first.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -