I'm getting an error saying that:
error c4700: unitialized local variable 'aCount' used
(as well as bCount
,cCount
,dCount
,fCount
). This is a example from C++ How to Program: Late Objects Version (7th Edition) by Deitel and Deitel I copied verbatim, don't see why its not working) Please help. Thank you.
edit: thank you everyone for your responses!
#include <iostream>
using namespace std;
int main()
{
int grade;
int aCount;
int bCount;
int cCount;
int dCount;
int fCount;
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\nNumber of students who received each letter grade:"
<< "\nA: " << aCount
<< "\nB: " << bCount
<< "\nC: " << cCount
<< "\nD: " << dCount
<< "\nF: " << fCount
<< endl;
}