Hello there, I am relatively new to programming. I am working on a program for my intro to cs class, but I am having trouble with it.
My program is supposed to calculate your grade for any class.
It asks for the total components (homework, quiz, exams etc.) and calculates the points for each component.
A problem i noticed is that the default constructor doesn't initialize any of the member variables i provided.
Another problem I came across is on the last step. Once i fill the vector with the objects, It gives me bogus values when i want them to be printed.
double Grade::computePercentage(int size)
{
cout << "Enter your scores: " << endl;
// create a vector, you don't have to put a fixed size -> because you push
vector<double> scoreTable;
//set your variables to default 0, if not you could have random numbers inside
double input = 0;
double userpoints = 0;
//go trough inputs like given size in paramenter
for(int i=0; i<size; i++){
cout << "Enter input: ";
cin >> input;
// userpoints = userpoints + input;
userpoints += input;
// push the input in vector-container, you dont have to resize
scoreTable.push_back(input);
}
//go trough vector with an iterator (pointer) and calc percentage of user
for(vector<double>::iterator iter = scoreTable.begin(); iter != scoreTable.end(); iter++){
userPercent = userpoints / maxPoints;
userPercent *= coursePercent;
}
return userPercent;
}
When you count a double with an int, the result ist int (splitted after the dot .)... pay attention to that... you have two possibilities... "cast" the int-variable when you calculate or declare it as double like I did... it's up to you...
then i have done changes in the readIn-function... you have to check if the entered totalAssignment ist not 0... if it's 0 you can't create the maxPoints...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void Grade::readIn()
{
cout << "Please put Course Name: ";
getline(cin, coursename);
cout << "Please put Course Percent (double): ";
cin >> coursePercent;
cout << "Please put Total Assignment (double): ";
cin >> totalAssignments;
if(totalAssignments == 0){
cout << "cannot calculate points in component, totalAssignemnts is 0!" << endl;
} else {
maxPoints = totalAssignments * 100;
}
}
I caught the mistake when i made when defining the constructor later. I tried emailing my professor but by the time he responds, the assignment might be overdue. But thanks for the feedback i was able to get the program going. Thank you guys!