If and else statement help?

Hey yall!

I started writing my first real program earlier and it was going well until I ran into this bug that has perplexed me for hours and I was hoping you guys can help. I'm sure my program is riddled with problems so any help, even if it doesn't concern my bug, will be greatly appreciated.
Now, onto the bug. I first look if the player has pushed 'S' and then present them with a difficulty choice. However, I only want the difficulty to be 1 - 10. When the difficulty inputted it within the boundaries, the program works fine. It's when the number is outside of 1 - 10. For some reason the rest of the program after it is triggered, even though I have an if statement checking gameStarted, which is by default false and is only turned on by the difficulty being within bounds.
Thanks for reading this far. I hope you understand and can help me with my problem. Again, I know this is not the best way to do this, so please give me suggestions. Thanks!

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
#include <iostream>



char entered;
int difficulty = 1;
int prevdiff = 1;
int constant = 1;
int population = 5;
int gold = 100;
int food = 20;

bool gameStarted = false;
int main()
{

	std::cout << "\t\t\nHello and Welcome!" << "\nEnter S to Start" << "\nEnter Q to Quit\n" << std::endl;
	while (std::cin) {
		std::cin >> entered;
		if (entered == 'S') {
			std::cout << "\n\nEnter a number to change your difficulty. (By default 1.)\n";
			std::cin >> difficulty;
			while (difficulty != prevdiff) {
				if (difficulty > 10 || difficulty < 1)
				{
					std::cout << "Invalid number. Please enter again.\n";
					difficulty = prevdiff;
					std::cout << "Current difficulty is " << difficulty << "\n";
				}
				else
				{
					std::cout << "\nDifficulty changed to " << difficulty << "\n";
					prevdiff = difficulty;
					gameStarted = true;
				}
			}

		}
		if (entered == 'Q') {
			return 0;
		}
			if (gameStarted = true)
			{
				std::cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
				std::cout << "\t\t\t\t\t\t\t\t  Population:" << population << "\n";
				std::cout << "Gold:" << gold << "\n";
				std::cout << "Food:" << food << "\n";
				std::cout << "Resources:" << "\n";
			
			}
		}
	}
On line 42 you have only one =, you wanted ==, like on line 39.
Thank you! That fixed it
Topic archived. No new replies allowed.