Restart A loop if Y/N

using the bool continueYN what code and where do i need for the program to restart if 1 is pressed and to quit if 2 is pressed? Also if someone could look at the rand() I have and tell me why each loop generates the same number and how to correct it that would be great!




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
49
50
51
52
53
54
55
56
57
58
59
int main()

{
	srand(time(0));
	cout << "Cheapo Math Blaster" << endl;
	cout << endl;
	cout << "You gain one point per correct answer and one point is lost per wrong answer" << endl;
		cout << "If Your score falls to zero the game is over" << endl;
	int score = 1;
	int answer;
	int Attempt=3;
	int Number1;
	int Number2;
	Number1 = rand() % 20 ;
	Number2 = rand() % 30;
	bool continueYN = true;
	while (continueYN)
	{

		while (score > 0)
		{

			cout << Number1 << "+" << Number2 << endl;
			cin >> answer;
			{
				if (answer == Number1 + Number2)
				{
					cout << "Correct" << endl;
					score++;
					Attempt++;
					cout << "Score" << score << endl;
				}
				if (answer > Number1 + Number2)
				{
					cout << "Incorrect" << endl;
					score--;
					Attempt--;
					cout << "Score" << score << endl;
				}
				if (answer < Number1 + Number2)
				{
					cout << "Incorrect" << endl;
					score--;
					Attempt--;
					cout << "Score" << score << endl;
				}


			}
		}
		
	}
	



	
		system("Pause");
}
Last edited on
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your
post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <>
formatting button.
Topic archived. No new replies allowed.