simple while loop not closing

I created a simple IF statement inside a while loop that can call 2 different methods depending on the key pressed.

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

bool open = true;


void option1() {
	std:: cout << "You selected option 1" << std:: endl << std:: endl;

}

void option2() {
	std:: cout << "You selected option 2" << std:: endl << std:: endl;
}


int main() {
	
	std:: string input;

	while(open = true){
		std:: cout << "Select an option, 1 or 2: ";
		std:: cin >> input;

		if(input == "1"){
			option1();
			open = false;
		}else if(input == "2"){
			option2();
			open = false;
		}else{
			std:: cout << "Please, try again!" << std:: endl;
		}
	}

}


the purpose of the loop is to close after it selections either 1 or 2 but it seems to just keep looping back.

Any suggestions?

I've tried a do-while loop with the same result.
while (open == true)
 
while(open)


= is the assignment operator. Every time your code hits this point it resets the value of open, even if you changed it.
A stupidly overlooked that.

Thanks abhishekm71!
Topic archived. No new replies allowed.