Help with writing grade program

I'm working on writing a grade program with 2 quizes, one midterm and one final exam. I need the program to ask for the data, output it back out and include the average numeric score and a final letter grade. I have to use a structure. So far, I have the structure and it asks for the data but it won't output anything. I have not yet tried to work on the output of a letter grade. Here's what I have so far. What am I missing to get it to output everything.

#include<iostream>
using namespace std;

struct studentRecord // collection of student grades
{
int quiz1, quiz2;
double midterm, finalExam, quizAve, score;
};

double calcResults (studentRecord);
void displayResults (studentRecord);


int main ()
{
studentRecord grades; //asks for grades
cout << "Enter first quiz score: " << endl;
cin >> grades.quiz1;
cout << "Enter second quiz score: " << endl;
cin >> grades.quiz2;
cout << "Enter Midterm score: " << endl;
cin >> grades.midterm;
cout << "Enter Final Exam score: " << endl;
cin >> grades.finalExam;


double calcResults (studentRecord grades); // calculates results
void displayResults (studentRecord grades); // displays results

return 0;
}

double calcResults (studentRecord grades)

{
double quiz1Percent, quiz2Percent, quizAve, score;
quiz1Percent = (grades.quiz1 * 100)/10;
quiz2Percent = (grades.quiz2 * 100)/10;
quizAve = (quiz1Percent + quiz2Percent)/2;
score = ((grades.quizAve * .25) + (grades.midterm * .25) + (grades.finalExam * .50))/3;

}
void displayResults (studentRecord grades)
{
double quiz1Percent;
double quiz2Percent;
double quizAve;
double score;
cout << "Quiz 1 is: " << quiz1Percent << endl;
cout << "Quiz 2 is: " << quiz2Percent << endl;
cout << "Midterm is: " << grades.midterm << endl;
cout << "Final Exam is: " << grades.finalExam << endl;
cout << "Average numeric score is: " << grades.score << endl;
}
I think you want your struct to be like this.
1
2
3
4
5
6
struct studentRecord // collection of student grades
{
int quiz1, quiz2;
double midterm, finalExam, quizAve, score;
double quiz1Percent,quiz2Percent,quizAve;
};

and you calc function to be like this.
1
2
3
4
5
6
double calcResults (studentRecord grades){
grades.quiz1Percent = (grades.quiz1 * 100)/10;
grades.quiz2Percent = (grades.quiz2 * 100)/10;
grades.quizAve = (grades.quiz1Percent + grades.quiz2Percent)/2;
grades.score = ((grades.quizAve * .25) + (grades.midterm * .25) + (grades.finalExam * .50))/3;
}

and your display function to be like this.
1
2
3
4
5
6
7
8
void displayResults (studentRecord grades)
{
cout << "Quiz 1 is: " << grades.quiz1Percent << endl;
cout << "Quiz 2 is: " << grades.quiz2Percent << endl;
cout << "Midterm is: " << grades.grades.midterm << endl;
cout << "Final Exam is: " << grades.finalExam << endl;
cout << "Average numeric score is: " << grades.score << endl;
}

other then that every thing looks fine I think from what I understand of what your after.
Last edited on
1
2
3
4
5
6
7
double calcResults (studentRecord grades)
{   double quiz1Percent, quiz2Percent, quizAve, score;
    quiz1Percent = (grades.quiz1 * 100)/10;
    quiz2Percent = (grades.quiz2 * 100)/10;
    quizAve = (quiz1Percent + quiz2Percent)/2;
    score = ((grades.quizAve * .25) + (grades.midterm * .25) + (grades.finalExam * .50))/3;
}

A few problrems here.
1) Your function doesn't return anything.
2) You're not using the return value, so why declare the function as returning a double?
3) The values you calculate in the function are all local and are lost when the function exits.

youare29 posted a calc function which tries to update studentRecord, but there is a problem with his code. grades is passed by value, therefore any changes to the struct are local and are lost when calcResults exits. Changing the function to pass grades by reference will fix the problem.
 
double calcResults (studentRecord & grades)


PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.


Last edited on
Topic archived. No new replies allowed.