A simple while loop that isn't working

I have this homework assignment that is really simple but for some reason i have something wrong in my code that isn't making it work. We are currently working on C and C++ string. This is what the question asks:

Write a while loop that continues to ask the user for a letter grade between A and F, excluding E, until the user enters an acceptable character.

This is what i have come up with.
Please help.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  int main ()
{
	//variables
	char letter;

	cout << "input a character between A through F excluding E" << endl;
	cin >> letter;

	while (letter != 'A' || 'B' || 'C' || 'D' || 'F')
	{
		cout << "enter a char" << endl;
		cin >> letter;
	}
	
	return 0;
}
Last edited on
Never mind i have figured it out!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main ()
{
	//variables
	char letter;

	cout << "input a character between A through F excluding E" << endl;
	cin >> letter;

	while (letter != 'A' && letter != 'B' && letter != 'C' && letter != 'D' &&
		letter != 'F')
	{
		cout << "enter a char" << endl;
		cin >> letter;
	}
	
	return 0;
}
Topic archived. No new replies allowed.