Advertisement
Kagalive

random-multi-q-v1

Oct 2nd, 2020
1,319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 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.  //generate 2 random ints
  18.  int a{ dis(engine) };
  19.  int b{ dis(engine) };
  20.  
  21.  
  22.  //output
  23.  cout << a << " * " << b << " = ? ";
  24.  int userAnswer{};
  25.  cin >> userAnswer;
  26.  
  27.  if (userAnswer == (a*b))
  28.  {
  29.    cout << "Correct!\n";
  30.  }
  31.  else
  32.  {
  33.    cout << "Wrong!\n";
  34.  }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement