Need help with Switch statement

I cannot seem to get this switch statement to work, I want there to be a condition that prompts the user to enter "yes" or "no" then using a switch statement if they pick the case where it says "yes" then the program continues to do its job, and then if they pick the case where they type no the program says "the choice is yours!" then closes. Can someone please tell me what I am doing wrong?

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
 void PrintIntro()
{
	char answer = NULL;
	
	cout << "Would you like to calculate the mean and medium of your grades?" << endl;
	cin >> answer;

	if (answer != 'yes' && answer != 'no')
	{
		cout << "Please enter yes or no" << endl;
		cin >> answer;
	
		switch (answer)
		{
		case 'yes':
			cout << "Okay let's continue" << endl;
			break;
		case 'no':
			cout << "The choice is yours!" << endl;
			break;
		}
	}

	
}
There is a difference between a character and a string
1
2
char answer;  // 'x', '8', 'A', are all characters. NB. Single quote
std::string choice;  // "You", "me", "yes", "no", are strings. NB. Double quote 


So in your case, you should use std::string answer and fix the quotation marks.
Topic archived. No new replies allowed.