class GradeBook
{
public:
GradeBook(string);
void setcoursename(string);
string getcoursename();
void displaymessage();
void inputgrades();
void displayGradeReport();
private:
string coursename;
int aCount;
int bCount;
int cCount;
int dCount;
int fCount;
};
void GradeBook::displaymessage(){
int grade;
cout<<"Enter Grade Letter, EOF to exit"<<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;
default:
cout<<"Incorrect letter grade, enter a new one."<<endl;
}
}
}
int main()
{
string coursename;
cout<<"Enter Coursename"<<endl;
cin>>coursename;
GradeBook gradebook1("coursename");
cout<<"Welcome to GradeBook for"<<gradebook1.getcoursename();
gradebook1.displaymessage();
gradebook1.displayGradeReport();
system("pause");
}
everytime i run it, right after i input the name of the course it automatically says incorrect grade, and everytime when i type something, such as a,or b it still says incorrect grade. Is there something wrong with my code? thanks
You'd probably want to use cin.ignore() rather than cin.get(). This shouldn't make a difference, but it is more intuitive (and probably slightly more efficient, though I wouldn't count on it).