Hi everyone!
I have been having problems with my program where I am supposed to calculate the total essay score. I was wondering why the listed error in the title shows up, along with another error which says "expression must have class type"? Here is the code from all three files:
(GradedActivity.h)
#ifndef GRADEDACTIVITY_H
#define GRADEDACTIVITY_H
//This is the class declaration for Graded Activity
class GradedActivity
{
private:
double score;
public:
GradedActivity()
{
score = 0.0;
}
GradedActivity(double s)
{
score = s;
}
void setScore(double s)
{
score = s;
}
double getScore() const
{
return score;
}
char getLetterGrade() const;
}g;
#endif
(GradedActivity.cpp)
#include "GradedActivity.h"
//This is the member function GradedActivity::getLetterGrade
char GradedActivity::getLetterGrade() const
{
char letterGrade; //This holds the letter Grade
//if statement containing mutator function
if (gram <= 30 && spel <= 20 && leng <= 20 && cont <= 30)
{
grammar = gram;
spelling = spel;
length = leng;
content = cont;
}
else
{
cout << "There was invalid input in one of the categories." << endl;
return;
}
}
double totalEssayScore()
{
return (grammar + spelling + length + content);
}
};
//The main function
int main()
{
Essay a;
char g;
cout << "Enter the values recieved for the grammar, spelling, correct length, and content sections: " << endl;
a.inital();
double total = a.totalEssayScore();
if (total >= 0 && total <= 100)
{
cout << "The numeric score for the essay is: " << total << endl;
g.setScore(total);
}
else
{
cout << "The score cannot be determined." << endl;
}
return 0;
}
int main()
{
Essay a;
char g;
cout << "Enter the values recieved for the grammar, spelling, correct length, and content sections: " << endl;
a.inital();
double total = a.totalEssayScore();
if (total >= 0 && total <= 100)
{
cout << "The numeric score for the essay is: " << total << endl;
/*->*/ g.setScore(total);
}
else
{
cout << "The score cannot be determined." << endl;
}
return 0;
}
Your trying to use a char like a class name declaration(like Essay) I think you meant to declare it as GradedActivity g;
Also when entering values, you can do: cin >> gram >> spel >> leng >> cont; just a small thing but makes things neater.