Advertisement
MeehoweCK

Untitled

Nov 20th, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int pobierz_int()
  6. {
  7.     int liczba;
  8.     cin >> liczba;
  9.  
  10.     while(cin.fail())      // zwraca prawdę jeśli do bufora wczytano nieprawidłową wartość (nieodpowiadającą zmiennej)
  11.     {
  12.         cout << "Wczytana liczba jest niepoprawna. Wpisz jeszcze raz liczbe calkowita: ";
  13.         cin.clear();        // czyści informację o błędzie
  14.         cin.sync();         // czyści bufor wejścia
  15.         cin >> liczba;
  16.     }
  17.     return liczba;
  18. }
  19.  
  20. int main()
  21. {
  22.     int liczba = pobierz_int();
  23.     cout << liczba << endl;
  24.  
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement