Function Call Help.

The average grade come out right, but the letter grade is not working right. Im guessing is the FUNCTION CALL, but im not having any luck trying to solve it. Can anyone give me some pointers?


[code]
#include <iostream>
#include <iomanip>
using namespace std;

void cal_grade(int mid, int finalEx, int paper, int group, int parti);
void letter_grade(int grade);

int main()
{
int mid = 0;
int finalEx=0;
int paper = 0;
int group = 0;
int parti = 0;


cout <<left<<setw(28)<< "Grade Components" ;
cout <<right <<setw(28) << "Weight" << endl;
cout << left<< setw(28) <<"Midterm";
cout << right <<setw(28) << "25%" << endl;
cout << left << setw(28) << "Final Exam";
cout << right << setw(28) << "25%" << endl;
cout << left << setw(28) << "Research Paper";
cout << right << setw(28) << "20%" << endl;
cout << left << setw(28) << "Group Project";
cout << right << setw(28) << "20%" << endl;
cout << left << setw(28) << "Participation";
cout << right << setw(28) << "10%" << endl;
cout << endl;

cout << "Enter the grade of the Midterm:" << endl;
cin >> mid;
cout << "Enter the grade of the Final Exam:" << endl;
cin >> finalEx;
cout << "Enter the grade of the Research Paper: " << endl;
cin >> paper;
cout << "Enter the grade of the Group Project: " << endl;
cin >> group;
cout << "Enter the grade for Participation: " << endl;
cin >> parti;

cal_grade(mid, finalEx, paper, group, parti);


}

void cal_grade(int mid, int finalEx, int paper, int group, int parti)
{
int midW = 25;
int finalExW = 25;
int paperW = 20;
int groupW = 20;
int partiW = 10;
int average;
average = ((mid*midW) + (finalEx*finalExW) + (paper*paperW) + (group*groupW) + (parti*partiW)) / (midW + finalExW + paperW + groupW + partiW);
letter_grade(average);
cout << "The grade is " << letter_grade << " with the average of " << average << " ." << endl;
}

void letter_grade(int average)
{
char letter;

if (average == 100|| average >=90)
letter = 'A';
else if (average >= 80 && average <= 89)
letter = 'B';
else if (average >= 70 && average <= 79)
letter = 'C';
else if (average >= 60 && average <= 69)
letter = 'D';
else
letter = 'F';


}
Last edited on
Your letter_grade function is a void function. Void functions do not return a value and that is why you are not getting a letter grade output.

You need to either add an output statement to letter_grade to display the letter or change the letter_grade function to a char function.
Thank you MrGoat
Topic archived. No new replies allowed.