Conditionals in conditionals not working

Making a gag-gift program for a friend... the programming follows.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	if (turn1lukas = 1) {
		int turn1lukascounter;
		cout << "Sorry. You lack the blue mana.\n\n";
		cout << "1. Play it anyway.\n";
		cout << "2. Choose not to play it\n\n";
		cout << "Type Your Choice: ";
		cin >> turn1lukascounter;

		if (turn1lukascounter = 1) {
			cout << "oh no.";
		}
		else if (turn1lukascounter = 2) {
			cout << "oh yes";
		}
	}


When it actually runs, if turn1lukascounter = 2, it still runs the program for if it equals 1...
Last edited on
It does. Thank you. I keep forgetting that I have to use == for comparing values.

While on a topic, could you answer one last question for me?

I learn from other's code. Someone wrote char name[50]. What does that [50] do? And why is it that instead of typing cin >> name , they wrote cin.getline(name, 50) ?
What does that [50] do?

It declares an array of 50 characters.

And why is it that instead of typing cin >> name , they wrote cin.getline(name, 50) ?

cin >> name will stop reading when it encounters the first white space. So if one enters "John Smith", cin >> will only parse "John". getline() will read up to a \n (or optional delimiter) for the specified number of characters. getline() does not terminate on the first whitespace, so getline() would return "John Smith".


Topic archived. No new replies allowed.