Creating A Simple Maths Game - Help!

Well I've Mad A Simple Maths Game But The Answers Are Fixed And I Need Help With A Way I Can Generate 2 Random 2 Digit Sums With A Random + - / or *

Please help!

Thanks,
Adim
Is this what you want?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;

int main()
{
    srand(time(NULL));
    int var1 = rand() % 100;
    int var2 = rand() % 100;
    int operation = rand() % 4;
    if (operation == 0)
        cout << var1 << " + " << var2 << " = " << var1 + var2 << endl;
    if (operation == 1)
        cout << var1 << " - " << var2 << " = " << var1 - var2 << endl;
    if (operation == 2)
        cout << var1 << " * " << var2 << " = " << var1 * var2 << endl;
    if (operation == 3)
        cout << var1 << " / " << var2 << " = " << var1 / var2 << endl;

    return 0;
}
Last edited on
Thank you very much! If only there was a thank user button I am very grateful
Topic archived. No new replies allowed.