I didn't find sollution:S I wrote program but I didn't indicate a.m.(a) or p.m.(p).

Write a function that gets a time in seconds as a parameter and returns the time in hours, minutes, seconds and a character indicating a.m.(a) or p.m.(p) .

Code:
```#include<stdio.h>

int duration(int time,int *hour, int *minutes, int *seconds)
{
char a,p;

*hour=time/3600;
*minutes=time%3600/60;
*seconds=time%3600%60;

}

int main(void)
{
int seconds,hour,min,sec;

printf("Enter a time in seconds(<=0 stop):");
scanf("%d",&seconds);

while(seconds>0)
{
duration(seconds,&hour,&min,&sec);
printf("Time is %d:%d:%d\n",hour,min,sec);

printf("Enter a time in seconds(<=0 stop):");
scanf("%d",&seconds);

}

return(0);
}```

2. Without knowing the actual starting time there is no way of knowing the time of day.

Jim

3. Originally Posted by jimblumberg
Without knowing the actual starting time there is no way of knowing the time of day.

Jim
example run:
------------

Enter a time in seconds (<=0 to stop): 45930
Time is 12:45:30 a.m.

Enter a time in seconds (<=0 to stop): 65987
Time is 6:19:47 p.m.

4. So your sample run knew the time of day to start with. No where in your program is there a starting time. Looking at your examples it appears that your starting time is midnight. So you need to use this fact to determine am or pm.

Jim

5. I think he is using seconds elapsed since midnight, if I read his duration function correctly. If that's the case, hour should be a number from 0-23. If it's less than 12, it's AM, between 12 and 23 inclusive, it's PM. The only trick is that if hour comes back as 0, you need to print 12.

6. Originally Posted by anduril462
I think he is using seconds elapsed since midnight, if I read his duration function correctly. If that's the case, hour should be a number from 0-23. If it's less than 12, it's AM, between 12 and 23 inclusive, it's PM. The only trick is that if hour comes back as 0, you need to print 12.
yes time>12 ----->p.m else a.m
ex: 65987 seconds /3600 >12 , its p.m else a.m but I didn't.

7. Code:
`printf("Time is %d:%02d:%02d %c.m.\n", hour, min, sec, "ap"[hour > 11]);`
Note the %02d so that each has leading zero if there is only 1 digit.

8. Do you not know how to write an if statement? Check your books and class notes. Read our tutorial and find some more on Google.

9. Originally Posted by nonoob
Code:
`printf("Time is %d:%02d:%02d %c.m.\n", hour, min, sec, "ap"[hour > 11]);`
Note the %02d so that each has leading zero if there is only 1 digit.
thank you very much! but this part must be "ap"[hour>12]

10. How would you go about adding this? I suggest you read the previous posts and try to implement a solution.

Jim