Jul 26, 2012 at 2:04am UTC
I build and run this and it says "EOF has not been declared" at line 19......... I typed the exact codes one by one.
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int grade,
aCount = 0,
bCount = 0,
cCount = 0,
dCount = 0,
fCount = 0;
cout << "Enter the letter grades." << endl
<< "Enter the EOF character to end input." << endl;
while ( ( grade = cin.get() ) != EOF ) {
switch ( grade ) {
case 'A' :
case 'a' :
++aCount;
break ;
case 'B' :
case 'b' :
++bCount;
break ;
case 'C' :
case 'c' :
++cCount;
break ;
case 'D' :
case 'd' :
++dCount;
break ;
case 'F' :
case 'f' :
++fCount;
break ;
case '\n' :
case '\t' :
case ' ' :
break ;
default :
cout << "Incorrect letter grade entered."
<< " Enter a new grade." << endl;
break ;
}
}
cout << "\n\nTotal for each letter grade are:"
<< "\nA: " << aCount
<< "\nB: " << bCount
<< "\nC: " << cCount
<< "\nD: " << dCount
<< "\nF: " << fCount << endl;
return 0;
}
Last edited on Jul 26, 2012 at 2:18am UTC
Jul 26, 2012 at 2:31am UTC
First: How do you type the EOF?
Second: EOF is not defined in your program anywhere.
Third: EOF stands for End Of File, where is your file?
Fourth: There is a few predefined EOF's but I'm not sure you want any of them for this.
Edit: Ignore the first comment, it's possible, but I still don't believe that's what you want.
You could try using while ((grade = cin.get()) != '\n' )
Last edited on Jul 26, 2012 at 2:41am UTC
Jul 26, 2012 at 2:50am UTC
Try while (std::cin>>grade)