...

Time

Xiang
01-22-2003, 03:49 PM
Dear sir,

I want to write a program that accepts a number of seconds and converts it to days, hours, minutes and seconds. Why my output is not correctly?

#include <stdio.h>
#include <conio.h>

void main()
{
int seconds;

clrscr();
printf("How many second?\n");
scanf("%i", &seconds);

printf("Day: %i\n", seconds/(60*24));

seconds=seconds%(60*24);
printf("Hours: %i\n", seconds/60);

seconds=seconds%60;
printf("Minutes: %i\n", seconds/60);

seconds=seconds%60;
printf("Seconds: %i\n", seconds/1);
getch();
}


Thanks


Xiang

codefox
01-23-2003, 02:55 PM
Maybe this would work
#include <stdio.h>
#include <conio.h>

void main()
{
long seconds;

clrscr();
printf("How many seconds? ");
scanf("%li", &seconds);

printf("Day: %i\n", (seconds / (60 * 60)) / 24);
printf("Hours: %i\n", (seconds / (60 * 60)) % 24);
printf("Minutes: %i\n", (seconds / 60) % 60);
printf("Seconds: %i\n", seconds % 60);

getch();
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum