Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Time

  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Malaysia
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Time

    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

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    India
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe this would work
    Code:
    #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();
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •