Kagalive icon

random-multi-q-v2

Kagalive | PRO | 10/02/20 11:25:51 PM UTC | 0 ⭐ | 2097 👁️ | Never ⏰ | []
C++ |

700 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 };
 
    
 
 
 
    //output
    cout << "Welcome to multiply\n";
    cout << "Enter -1 to quit the program!\n";
    int userAnswer{};
    while (userAnswer != -1) {
        //generate 2 random ints
        int a{ dis(engine) };
        int b{ dis(engine) };
        cout << a << " * " << b << " = ? ";
 
        cin >> userAnswer;
 
        if (userAnswer == (a * b))
        {
            cout << "Correct!\n";
        }
        else if (userAnswer == -1)
        {
            cout << "Goodbye!\n";
        }
        else
        {
            cout << "Wrong!\n";
        }
    }
}

Comments