Advertisement
BeloMaximka

Belov_HW_O37

Oct 25th, 2021
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int main()
  5. {
  6.     try
  7.     {
  8.         cout << "Enter size: ";
  9.         int size;
  10.         cin >> size;
  11.         if (size <= 0) throw string("Incorrect array size");
  12.  
  13.         vector<int> arr(size);
  14.         cout << "Arr values:\n";
  15.  
  16.         for (auto& temp : arr)
  17.         {
  18.             int val = rand();
  19.             cout << val << endl;
  20.             if (val == 0) throw 0;
  21.             temp = val;
  22.         }
  23.     }
  24.     catch (string e)
  25.     {
  26.         cout << "Error: " << e;
  27.     }
  28.     catch (int e)
  29.     {
  30.         cout << "Error! Code: " << e;
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement