Thread: Converting MInutes to Hours and MInutes

  1. #1
    Unregistered
    Guest

    Converting MInutes to Hours and MInutes

    I am working on a project in a class at school and I am required to convert a unit of minutes (ie 130 Minutes) to Hours and Minutes (ie 2 HOurs and 10 Minutes). If anyone knows a trick to do this please let me know.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    6
    Try the following code:


    #include <stdio.h>
    #include <stdlib.h>

    int numMinutes = 103; /* ie 1 hour 43 minutes */

    int main ( void )
    {
    if ( (numMinutes / 60) == 1 ) /* display 'x' hour... */
    printf("%01d hour",numMinutes/60);
    else /* display 'x' hours .... */
    printf("%01d hours",numMinutes/60);

    if ( (numMinutes % 60) == 1) /* display 'x' minute... */
    printf(" %01d minute\n",numMinutes%60);
    else /* display 'x' minutes....*/
    printf(" %01d minutes\n",numMinutes%60);

    return 0;
    }

  3. #3
    Unregistered
    Guest

    Cool

    #include<stdio.h>

    int time = 0; /* Total time in minutes */
    int minutes = 0;
    int hours = 0;

    int main()
    {

    time = 130; /* Set time to total minutes */

    minutes = time % 60; /* Divide by 60 minutes and and take
    the ramainder as left over minutes */

    /* remove left over minutes from time to get even number and
    divide by 60 to get total hours */

    hours = (time - minutes) / 60;

    printf("Total minutes %d = %d hours and %d minutes\n", time,
    hours, minutes);

    return(0);
    }

    Hope that chunk of code helps u with your school work

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    9
    int min;
    int hr;


    min=130;


    while(min>60)
    {
    hr++;
    min=min-60;
    }/***********will loop twice leaving 2 in hr and10 in min*/
    good luck.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Minute to hour/minute conversion program
    By Remius in forum C Programming
    Replies: 7
    Last Post: 12-29-2007, 08:39 AM
  2. Time between Military Hours
    By StarOrbs in forum C++ Programming
    Replies: 18
    Last Post: 03-01-2005, 06:46 PM
  3. Algo for create hours and minutes with given seconds
    By BianConiglio in forum C Programming
    Replies: 6
    Last Post: 05-30-2004, 06:50 PM
  4. Difference b/ween hours into minutes??
    By CodeFuse in forum C++ Programming
    Replies: 2
    Last Post: 03-22-2003, 02:01 AM
  5. switch hours and minutes
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 07-08-2002, 11:30 PM