Advertisement
MeehoweCK

Untitled

Mar 21st, 2023
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     cout << "Podaj liczbe calkowita: ";
  8.     int liczba;
  9.     cin >> liczba;
  10.  
  11.     // sprawdzenie błędu bufora
  12.     if(cin.fail())      // cin.fail() zwraca prawdę (true) jeśli w buforze wejścia (cin) jest błąd
  13.     {
  14.         cout << "Podales niepoprawna wartosc. Wpisz jeszcze raz: ";
  15.         cin.clear();                // usunięcie informacji o błędzie
  16.         cin.ignore(99999, '\n');    // usunięcie informacji z bufora wejścia
  17.         cin >> liczba;
  18.     }
  19.  
  20.     cout << "Podales liczbe " << liczba << endl;
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement