Program should choose randomly...

I'm brand new to programming. My program runs but it's not what my assignment is asking me to do.

It says that the program should choose whether the problem is addition or subtraction.
Mine displays both.
Appreciate any help or tips
Thanks.


Here is my code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  #include<iostream>
#include<ctime>
#include<iomanip>
#include<cstdlib>

using namespace std;

int main()
{
	int randomNum1, randomNum2;
	int studentTotal, tutorTotal;

	int seed = time(0);

	srand(seed);

	//generates random number
	randomNum1 = 100 + rand() % 500;
	randomNum2 = 100 + rand() % 500;

	//Displays the addition
	cout << setw(5) << randomNum1 << endl;
	cout << setw(2) << "+" << randomNum2 << endl;
	cout << "-----------\n";
	tutorTotal = randomNum1 + randomNum2;
	cin >> studentTotal;

	if (studentTotal == tutorTotal)
		cout << "\nCongratulations!\n";
	else
		cout << "The answer is NOT correct. The correct answer is " << tutorTotal << endl << endl;

	//displays the subtraction
	cout << setw(5) << randomNum1 << endl;
	cout << setw(2) << "-" << randomNum2 << endl;
	cout << "-----------\n";
	tutorTotal = randomNum1 - randomNum2;
	cin >> studentTotal;

	if (studentTotal == tutorTotal)
		cout << "\nCongratulations!\n";
	else
		cout << "The answer is NOT correct. The correct answer is " << tutorTotal << endl;

	system("pause");

	return 0;
}
You haven't written any piece of code that determines whether or not it should be addition or subtraction.

Generate 1 more random number, that is either equal to 1 or 2. If it is equal to 1, only run the addition part of the code, if it is equal to 2, run the subtraction part.
Topic archived. No new replies allowed.