Advertisement
mateusz1239196

C++ Simple 'Clock'

Jan 4th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. //zmienne
  7. short g,m,s;
  8. int main()
  9. {  
  10.     //ustawienie godziny
  11.     cout<<"Podaj godzine {GG MM SS}, lub wpisz dowolny znak aby zaczac odliczac od zera!";
  12.     cin>> g;
  13.     cin>> m;
  14.     cin>> s;
  15.    
  16.     //sprawdza czy godzina została podana prawidłowo
  17.    
  18.     if (g<0 || g>23)
  19.     {
  20.         cout<<"Godzina zostala podana w zly sposob."<<endl;
  21.         return main();
  22.     }
  23.      
  24.     if (m<0 || m>59 )
  25.     {
  26.         cout<<"Godzina zostala podana w zly sposob."<<endl;
  27.         return main();
  28.     }
  29.    
  30.     if (s<0 || s>59)
  31.     {
  32.         cout<<"Godzina zostala podana w zly sposob."<<endl;
  33.         return main();
  34.     }
  35.    
  36.     //zegar
  37.     while(true)
  38.     {
  39.            s++;
  40.            system("cls");
  41.         if(s==60)
  42.         {
  43.                  m++;
  44.                  s=0;
  45.         }
  46.         if (m==60)
  47.         {
  48.                   g++;
  49.                   m=0;
  50.         }
  51.         if (g==24)
  52.         {
  53.                   s=0;
  54.                   m=0;
  55.                   g=0;
  56.         }
  57.                                        
  58.           cout << setfill('0') << setw(2) << g<<":"<< setfill('0') << setw(2) << m <<":"<< setfill('0') << setw(2) << s << endl;
  59.            Sleep(1000);
  60.  
  61.         }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement