Hi! - I'm only a beginner, but I need some help with this problem.
I'm writing a program that converts seconds to hours and minutes - That works fine! But if I write:
3700 seconds
It answers
That equals to: 1 hours, 1 minutes and 40 seconds.
I now want my program to write
1 hour, 1 minute and 40 seconds.
And if there is no hours at all it should only write
400 seconds equals 6 minutes and 40 seconds.
To sum up: The program shall write hour/hours minute/minutes second/seconds correct.
I've made one succesfull program, but it was written with 27 "if-statements" and I know there is a better way.
So...Code:#include <stdio.h> int main(void) { int sec, secs, minute, hour, rest; printf("Type in the number of seconds:"); scanf("%d", &sec); hour = sec/3600; rest = sec%3600; minute = rest/60; secs = rest%60; printf("That equals to %d hours, %d minutes og %d seconds. \n", hour, minute, secs); return (0); }
Any good advice on how to make the program know when to write hour or hours?
/Fedryan