Need help with a switch inside a while loop

Can anyone tell me what i'm doing wrong the code is suppose to take a grade and loop until it receives anything that is not a grade. it compiles with no errors.
when it runs it will take any grade and stay stuck. Anything that isnt a grade will reply incorrect but not exit the while.

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
53
54
55
 #include<iostream>
#include<string>
using namespace std;
int main()
{
	int grade(0), aC(0), bC(0), cC(0), dC(0), fC(0);

	cout << "enter the grades" <<endl;
	while (( grade = cin.get()) != EOF )
	{	switch (grade)
		{
			case 'A' :
			case 'a' :
			++aC;
			break;

			case 'B' :
			case 'b' :
			++bC;
			break;

			case 'C' :
			case 'c' :
			++cC;
			break;

			case 'D' :
			case 'd' :
			++dC;
			break;

			case 'F' :
			case 'f' :
			++fC;
			break;

			case '\n' :
			case '\t' :
			case ' ' :
			break;

			default:
				cout <<"incorrect letter" << endl ;
				break;


		}        
	}
	cout<< "this is A: "<< aC <<endl;
	cout<< "this is b: "<< bC <<endl;
	cout<< "this is c: "<< cC <<endl;
	cout<< "this is d: "<< dC <<endl;
	cout<< "this is f: "<< fC <<endl;

}
All the breaks are within the switch; none of them breaks from the while loop. The only thing that can quit the loop is grade becoming EOF.
how can i set that eof value i thought the eof was like a built in function with a preset value that couldnt be changed. do i set default to say grade = eof to break?
Use a separate bool variable.
Topic archived. No new replies allowed.