Advertisement
dxvmxnd

Untitled

Sep 16th, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int num1, num2;
  7. int sum;
  8. bool isNotCorrect;
  9.  
  10. cout << "Сумма двух чисел бла бла бла" << endl;
  11.  
  12.  
  13. do {
  14. cout << " Введите число 1" << endl;
  15. isNotCorrect = false;
  16. cin >> num1;
  17. if(cin.fail() or (num1 < 1)) {
  18. cout << "Ошибка" << endl;
  19. isNotCorrect = true;
  20. cin.clear();
  21. while(cin.get() != '\n');
  22. }
  23.  
  24. } while(isNotCorrect);
  25.  
  26. do {
  27. cout << " Введите число 1" << endl;
  28. isNotCorrect = false;
  29. cin >> num2;
  30. if(cin.fail() or (num2 < 1)) {
  31. cout << "Ошибка" << endl;
  32. isNotCorrect = true;
  33. cin.clear();
  34. while(cin.get() != '\n');
  35. }
  36.  
  37. } while(isNotCorrect);
  38.  
  39.  
  40. sum = num1 + num2;
  41.  
  42. cout << sum;
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement