Converts time in minutes to time in hours and minutes. - C Operator

C examples for Operator:Arithmetic Operator

Introduction

Use #define or const to create a symbolic constant for 60.

Use a while loop to allow the user to enter values repeatedly and terminate the loop if a value for the time of 0 or less is entered.

Demo Code

#include <stdio.h>

const int MINUTES_PER_HOUR = 60;

int main(void)
{
  int minutes;//from w  ww.j a v  a2 s.c o m

  printf("Enter an amount of time in minutes: "); // get first input
  scanf("%d", &minutes);
    
  while (minutes > 0){
    printf("%d minute(s) is %d hour(s) and %d minute(s).\n",
         minutes,
         minutes / MINUTES_PER_HOUR, // hours
         minutes % MINUTES_PER_HOUR); // minutes

    printf("Enter an amount of time in minutes: "); // get new input
    scanf("%d", &minutes);
  }

  return 0;
}

Result


Related Tutorials