Advertisement
J2112O

Convert minutes to hour(s) and minutes

Apr 30th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.19 KB | None | 0 0
  1.  1 // ex1.c --- converts time in minutes to time in hours and minutes              
  2.   2 #include <stdio.h>                                                              
  3.   3 #include <stdlib.h>                                                              
  4.   4 #define CONTROL 60                                                              
  5.   5                                                                                  
  6.   6 int main(void)                                                                  
  7.   7 {                                                                                
  8.   8     int min;                                                                    
  9.   9     float hour;                                                                  
  10.  10                                                                                  
  11.  11     printf("Enter a time in minutes: ");                                        
  12.  12     scanf("%d", &min);                                                          
  13.  13     double extraMin = min - 60; // leftover minutes in a hour  
  14.         hour = min/CONTROL                
  15.  14                                                                                                                    
  16.  15                                                                                
  17.  16     if(min > 0)                                                                  
  18.  17     {                                                                            
  19.  18         printf("That's %1.f hour(s) and %2.f minutes.\n",                        
  20.  19             hour, extraMin);                                                    
  21.  20     }                                                                            
  22.  21     else                                                                        
  23.  22     {                                                                            
  24.  23         printf("Please enter a value more than 0.\n");                          
  25.  24     }                                                                            
  26.  25     return 0;                                                                    
  27.  26 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement