Kagalive icon

random-multi-q-v1

Kagalive | PRO | 10/02/20 10:48:19 PM UTC | 0 ⭐ | 2120 👁️ | Never ⏰ | []
C++ |

510 B

|

None

|

0 👍

/

0 👎

#include <iostream>
#include <random>
using namespace std;
 
int main()
{ 
 
  //seed random gen
  random_device seed{};
 
  // random gen
  mt19937 engine{ seed() };
 
 //uniform distribution
 uniform_int_distribution<> dis{1,10};
 
 //generate 2 random ints
 int a{ dis(engine) };
 int b{ dis(engine) };
 
 
 //output
 cout << a << " * " << b << " = ? ";
 int userAnswer{};
 cin >> userAnswer;
 
 if (userAnswer == (a*b))
 {
   cout << "Correct!\n";
 }
 else
 {
   cout << "Wrong!\n";
 }
 
}

Comments