ok so this program is supposed to end up calculating a final letter grade based on these 4 assessments. I have all the required functions but it isn't working out right and I am getting frustrated. I am new to this so i was wondering if anyone has any pointers to clean this up! thanks!
double grading::getscores()
{
double quiz1,quiz2,midterm,finalexam;
cout << "Enter the score for quiz #1:\n";
cin >> quiz1;
cout << "Enter the score for quiz #2:\n";
cin >> quiz2;
cout << "Enter the score for the midterm:\n";
cin >> midterm;
cout<< "Enter the score for the final exam:\n";
cin >> finalexam;
}
void grading::finalgrade(double total)
{
cout << "The final grade is:" << total << " percent.";
if (total >= 90)
cout << "The student's grade is an A.\n";
else if ((total < 90) && (total >= 80))
cout << "The student's grade is a B.\n";
else if ((total < 80) && (total >= 70))
cout << "The student's grade is a C.\n";
else if ((total < 70) && (total >= 60))
cout << "The student's grade is a D.\n";
else
cout << "The student's grade is an F.\n";
}
Have you even compiled what you posted? You have numerous compile errors.
Line 8: terminate the statement with; not :
Lines 9-10: These need ();
Line 34: Get rid of the types in the function call. finalexam is undefined.
Line 39: Implementation does not match the function declaration at line 8.
Line 41: These values will be lost when the function exits.
Line 52: Implementation does not match the function call.
Line 67: You are declaring total as a local variable. Your calculation at line 72 is not being saved. total goes out of scope when you exit the function.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
cout << "Enter the score for quiz #1:\n";
cin >> quiz1;
cout << "Enter the score for quiz #2:\n";
cin >> quiz2;
cout << "Enter the score for the midterm:\n";
cin >> midterm;
cout<< "Enter the score for the final exam:\n";
cin >> finalexam;
}
void grading::finalgrade(double &total)
{
cout << "The final grade is:" << total << " percent.";
if (total >= 90)
cout << "The student's grade is an A.\n";
else if ((total < 90) && (total >= 80))
cout << "The student's grade is a B.\n";
else if ((total < 80) && (total >= 70))
cout << "The student's grade is a C.\n";
else if ((total < 70) && (total >= 60))
cout << "The student's grade is a D.\n";
else
cout << "The student's grade is an F.\n";
}
your setScores should do what your getScores is doing. getScores shouldn't change anything it should only be used to get scores, get functions can usually be consts because of this while set functions purpose is usually to set the values of your private data members which you then utilize in your other functions. generally i don't like doing any I/O in a set function unless really necessary either, so in main you can set the values and run a loop that ends when the amount of students specified by user is reached. then pass the values to setGrades each time around the loop. you don't need to declare new variables in your set function, those will not hold values, just get rid of that and the set function will work as is to give values to the private members.