Advertisement
xlujiax

Formato Reloj

Aug 23rd, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <cstdio>
  3.  
  4.  
  5. /*
  6.  void calcHora(float _time, int *hour, int * minutes, int *seconds){
  7.         *hour = (int)_time % 24;
  8.  *      float min_float = ((_time - (int)_time)*60;
  9.  *      *minutes = (int)min_float;
  10.  *      *seconds = (min_float - *minutes)*60;
  11.  *      *hour = (int)_time %24;
  12.  * }
  13.  
  14.  */
  15.  
  16.  
  17. /*
  18.  *void calcHora(float _time, int *hour, int * minutes, int *seconds){
  19.  *  int sec = _time*3600;
  20.  * *hour =
  21.  * }
  22.  */
  23.  
  24. void calcHora(float horaO){
  25.     int horas;
  26.     int minutos;
  27.     int segundos;
  28.    
  29.     float auxMin;
  30.     float auxSeg;
  31.    
  32.     horas = (int)horaO;
  33.     printf("Horas: %d \n",horas);
  34.     auxMin = ((horaO - horas))*60; //30.6
  35.     //printf("%f \n",auxMin);
  36.     minutos = (int)auxMin;
  37.     printf("Minutos: %d\n",minutos);
  38.     auxSeg = ((auxMin - minutos))*60;
  39.     //printf("%f \n",auxSeg);
  40.     segundos = (int)auxSeg;
  41.     printf("Segundos: %d\n",segundos);
  42. }
  43.  
  44. int main(int argc, char** argv) {
  45.     float horaO;
  46.     float Offset;
  47.     float conv;
  48.     float auxMin;
  49.     float auxSeg;
  50.     float faltante;
  51.    
  52.    
  53.     int horas;
  54.     int minutos;
  55.     int segundos;
  56.    
  57.    
  58.     horaO = 23.51;
  59.     Offset = 3.56;
  60.    
  61.     printf("Hora Original: \n");
  62.    
  63.     calcHora(horaO);  //calcHora(horaO, &minutes, &seconds);
  64.     printf("\n");
  65.    
  66.     printf("Hora Original +  Offset: \n");
  67.    
  68.     faltante = 24 - horaO;
  69.     if (faltante > Offset) {
  70.         horaO = horaO + Offset;
  71.         calcHora(horaO);
  72.     }else if (faltante == Offset){
  73.         calcHora(0.0);        
  74.     }else{
  75.         horaO = Offset - faltante;
  76.         calcHora(horaO);
  77.     }
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement