Advertisement
F_THIAGO

Lista I - Questão 7

Apr 19th, 2019
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. /*
  2. *   7] Fazer um programa em C++ para ler a hora, minuto e segundo e converter tudo para
  3. * segundos.
  4. */
  5.  
  6. #include <iostream>
  7.  
  8. using std::cout;
  9. using std::cin;
  10.  
  11. int main( void )
  12. {
  13.     unsigned short hora = 0;
  14.     unsigned short minutos = 0;
  15.     unsigned short segundos = 0;
  16.     unsigned long totalSegundos = 0;
  17.    
  18.     // ============ Entrada de dados ==============
  19.     do
  20.     {
  21.         cout << "\nHora (0-23): ";
  22.         cin  >> hora;
  23.     }while( !(hora >= 0 && hora <= 23) );
  24.    
  25.     do
  26.     {
  27.         cout << "\nminutos (0-59): ";
  28.         cin  >> minutos;       
  29.     }while( !(minutos >= 0 && minutos <= 59) );
  30.    
  31.     do
  32.     {
  33.         cout << "\nsegundos (0-59): ";
  34.         cin  >> segundos;      
  35.     }while( !(segundos >= 0 && segundos <= 59 ) );
  36.    
  37.     // Calcula o total de segundos
  38.     totalSegundos = hora*60*60 + minutos*60 + segundos;
  39.    
  40.     // ========= Saida de dados ==========
  41.     cout << "\nHora: " << hora << "h:" << minutos << "min:" << segundos << "s = " << totalSegundos << "s\n";
  42.    
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement