Advertisement
axyd

Lab 7, part 2

May 5th, 2016
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. using namespace std;
  4.  
  5. void err(int);
  6.  
  7. int main(){
  8.     char again = 'y';
  9.     const int size = 15;
  10.     int n = 0, arrayN[size];
  11.  
  12.     while (again == 'y' || again == 'Y'){
  13.         cout << "\nEnter a number: ";
  14.         cin >> n;
  15.  
  16.         while (cin.fail() || n < 1 || n > 100){
  17.             err(n);
  18.             cout << "Enter a number: ";
  19.             cin >> n;
  20.         }
  21.  
  22.         mt19937 prng{ random_device{} () }; //garanteed random
  23.         uniform_int_distribution<> dist(1, 100); //range
  24.  
  25.         cout << "\nRandom numbers greater than " << n << " are: ";
  26.         for (int i = 0; i < size; i++){
  27.             arrayN[i] = dist(prng);
  28.             if (arrayN[i] > n)
  29.                 cout << arrayN[i] << " ";
  30.         }
  31.        
  32.         cout << "\n\nDrawn numbers: "; //show drawn numbers
  33.         for (int j = 0; j < size; j++)
  34.             cout << arrayN[j] << " ";
  35.  
  36.         cout << "\n\n\t\t ### Enter Y or y to repeat: ";
  37.         cin >> again;
  38.     }
  39. }
  40.  
  41. void err(int nr){ //fix letter, <1 and >100
  42.     if (cin.fail())
  43.         cout << "\t\t/!\\ Not a number /!\\\n";
  44.     else if (nr < 1)
  45.         cout << "\t\t/!\\ Negative number /!\\\n";
  46.     else if (nr > 100)
  47.         cout << "\t\t/!\\ Greater than 100 /!\\\n";
  48.     cin.clear();
  49.     fflush(stdin);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement