Thread: Very Curious

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    3

    Very Curious

    So im trying to figure out how to make a program that converts seconds to hours, minutes, and seconds....but I cant seem to get how when i run the program.. the program will say enter the seconds and the output will be the seconds are equal to hours minutes and seconds. help...its bugging me that i cant figure it out. what should i add to this code :

    Code:
    #include <stdio.h>
     
    #define NROFITEMS 3
     
    int values[NROFITEMS] = {3600, 60, 1};
    int count[NROFITEMS];
    char *names[NROFITEMS] = {"hours", "minutes", "seconds"};
     
    int main (int argc, const char * argv[])
    {
     
        int i, total = 6789;
     
        for (i = 0; i < NROFITEMS; ++i) {
            count[i] = total / values[i];
            total -= count[i] * values[i];
        }
         
        for (i = 0; i < NROFITEMS; ++i) {
            printf("\n%s: %i", names[i], count[i]);
        }
         
        return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    So
    a) what output did you get?
    b) what output did you expect?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. jus curious
    By Obelisk in forum C Programming
    Replies: 3
    Last Post: 10-06-2009, 02:30 AM
  2. Just curious
    By Chaplin27 in forum C++ Programming
    Replies: 3
    Last Post: 09-10-2004, 10:57 AM
  3. Just curious
    By afreedboy in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-21-2004, 11:10 PM
  4. Just curious
    By CAP in forum C Programming
    Replies: 9
    Last Post: 09-08-2002, 05:15 PM
  5. Just Curious!?!
    By JLTaylor in forum C Programming
    Replies: 3
    Last Post: 02-18-2002, 09:17 AM