-
parameter passing..??
I am having trouble figuring out how to get this program to work correctly and was wondering if someone could give me a little guidance? I know the problem is in the last function Grade::getWeightedGrade() but I can't figure out what I am doing wrong. The program runs correctly but instead of returning the right score it returns zero. The score is supposed to be based upon the ( score of the test * (weight / 100) for both grade1 and grade2 and then these totals are added together to give the final score....
Here is what it should run like:
Enter Type: Midterm
Enter Score: 86
Enter Weight: .40
Enter Type: Final
Enter Score: 97
Enter Weight: .60
Your grades are as follows:
Midterm 86, which counts 40%
Final 97, which counts 60%
Your final grade is: 92.6
Code:
#include <iostream>
#include <string>
using namespace std;
class Grade
{
public:
void enterGradeInfo();
void showGradeInfo();
double getWeightedGrade();
private:
int mWeight;
int mScore;
string mType;
};
int main()
{
Grade grade1;
Grade grade2;
grade1.enterGradeInfo();
grade2.enterGradeInfo();
cout << "Your grades are as follows:" << endl;
grade1.showGradeInfo();
grade2.showGradeInfo();
cout << "Your final grade is " << grade1.getWeightedGrade + grade2.getWeightedGrade;
cout << endl;
system("pause");
return 0;
}
void Grade::enterGradeInfo()
{
cout << "Enter type: ";
cin >> mType;
cout << endl;
cout << "Enter Score: ";
cin >> mScore;
cout << endl;
cout << "Enter weight: ";
cin >> mWeight;
cout << endl;
}
void Grade::showGradeInfo()
{
cout << mType << " which counts for " << mWeight << "%" << endl;
}
double Grade::getWeightedGrade()
{
return mScore * (mWeight/100) ;
}
-
Without looking too much could it be precision of your variables?
int mWeight;
int mScore;
it could be rounding your math off to ZERO ?
try switching them to double or
Code:
mScore * (mWeight/100.0f)
or
float(mScore) * (mWeight/100.0f)
mWeight/100 = 0.5 = round off to zero I'm guessing
m_Score * 0 = ZERO
etc..
-
getWeightedGrade is a method, and needs to be called like this (you forgot the parentheses):
Code:
cout << "Your final grade is " << grade1.getWeightedGrade() + grade2.getWeightedGrade();
-
thank you
wow one little decimal after all of that.... thank you so much