Advertisement
Kagalive

random-multi-q-v2

Oct 2nd, 2020
1,625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8.     //seed random gen
  9.     random_device seed{};
  10.  
  11.     // random gen
  12.     mt19937 engine{ seed() };
  13.  
  14.     //uniform distribution
  15.     uniform_int_distribution<> dis{ 1,10 };
  16.  
  17.    
  18.  
  19.  
  20.  
  21.     //output
  22.     cout << "Welcome to multiply\n";
  23.     cout << "Enter -1 to quit the program!\n";
  24.     int userAnswer{};
  25.     while (userAnswer != -1) {
  26.         //generate 2 random ints
  27.         int a{ dis(engine) };
  28.         int b{ dis(engine) };
  29.         cout << a << " * " << b << " = ? ";
  30.  
  31.         cin >> userAnswer;
  32.  
  33.         if (userAnswer == (a * b))
  34.         {
  35.             cout << "Correct!\n";
  36.         }
  37.         else if (userAnswer == -1)
  38.         {
  39.             cout << "Goodbye!\n";
  40.         }
  41.         else
  42.         {
  43.             cout << "Wrong!\n";
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement