Daved, thanks for the help... unfortunetely I cannot use what you have provided me
This is homework (if you couldn't guess :P ), and we aren't allowed to use anything that hasn't been covered in class up until this point.
There's another thing that's bothering me. There is an example in the book (a gradebook) that uses an integer type, and allows for entering characters without going into a fail state... here's the code:
Code:
void GradeBook::inputGrades()
{
int grade; // grade entered by user
cout << "Enter the letter grades." << endl
<< "Enter the EOF character to end input." << endl;
// loop until user types end-of-file key sequence
while ( ( grade = cin.get() ) != EOF )
{
// determine which grade was entered
switch ( grade ) // switch statement nested in while
{
case 'A': // grade was uppercase A
case 'a': // or lowercase a
aCount++; // increment aCount
break; // necessary to exit switch
case 'B': // grade was uppercase B
case 'b': // or lowercase b
bCount++; // increment bCount
break; // exit switch
case 'C': // grade was uppercase C
case 'c': // or lowercase c
cCount++; // increment cCount
break; // exit switch
case 'D': // grade was uppercase D
case 'd': // or lowercase d
dCount++; // increment dCount
break; // exit switch
case 'F': // grade was uppercase F
case 'f': // or lowercase f
fCount++; // increment fCount
break; // exit switch
case '\n': // ignore newlines,
case '\t': // tabs,
case ' ': // and spaces in input
break; // exit switch
default: // catch all other characters
cout << "Incorrect letter grade entered."
<< " Enter a new grade." << endl;
break; // optional; will exit switch anyway
} // end switch
} // end while
} // end function inputGrades
... I just don't get it. I ran this program and input characters that weren't allowed for in the case section (such as g and t) and it successfully defaulted...