I'm really new to C and was wondering if you guys could help me find maybe a better or more efficent way of writing the code i just made, it's a program that'll take input from the user in the format of 8934 seconds and convert it to 2 Hours 45 minutes and 23 seconds.....i think i'm using the wrong variable type for local variable that holds 86400, cause i believe it only goes up to 32000 though, but i can't get it to work when i try long int;
Code:
#include <stdio.h>
int main()
{
int x,d,f,a;
int c;
printf("This here is a program to transfer seconds into Hours Minutes Second format-\n");
printf("Seconds: ");
scanf("%d", &c);
if( c <= 60) {
printf("%d Seconds",c);
sleep(10);
}
else if( c >= 60 && c <= 3600) {
x = c/60;
d = c%60;
printf("%d Minutes %d Seconds",x, d);
sleep(1);
}
else if(c >=3600 && c<= 86400) {
x = c/3600;
d = c%3600;
f = d / 60;
a = d % f;
printf("%d Hours %d Minutes %d Seconds",x,f,a);
sleep(4);
}
else {
print("That's more seconds than in a day ");
sleep(4);
}
}
Thankyou alot!