Advertisement
MeehoweCK

Untitled

Mar 30th, 2023
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int liczba;
  8.     cout << "Podaj liczbe calkowita: ";
  9.     cin >> liczba;
  10.  
  11.     while(cin.fail())           // zwraca true jeśli dane wejściowe są niepoprawne
  12.     {
  13.         cin.clear();        // usunięcie informacji o błędzie
  14.         cin.ignore(9999, '\n');     // wyczyszczenie bufora wejścia
  15.         cout << "Wpisano niepoprawna liczbe, wpisz jeszcze raz: ";
  16.         cin >> liczba;
  17.     }
  18.  
  19.     cout << "Wpisana liczba to " << liczba << endl;
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement