This was a past assignment (it was last week's assignment), but I couldn't complete it. Could anyone help me finish it? I'm new to the function calls. The professor said I didn't call them from main properly. Although I've already received a grade on this assignment, we now have a chance to get extra credit on the same type of assignment. I need to learn this so if anyone can help me with it, I would greatly appreciate it.

#include <iostream>
#include <iomanip>

using namespace std;


int getExam1Scores(int, float);
int getExam2Scores(int, float);
void averageGrades(float[], int, float[]);
float Exam1Grade;
float Exam2Grade;
float AverageGrade;
float calculateAverage;
float GradeAverage;
float AvgExam2Grade;
float AvgExam1Grade;
int rows;
int cols;



void display(int);


int main ()
{

    const int NUM_ROWS = 10;
	const int NUM_COLS = 4;
	double NumStudents[NUM_ROWS][NUM_COLS];  //Array with 10 rows and 4 columns

	


cout << "This program will allow the user to input " << endl;
	cout << "2 exam scores for 10 students and those scores " << endl;
	cout << "will be averaged.  The results will be " << endl;
	cout << "diplayed in a two-dimensional array." << endl;

//Nested loops to fill array with students information.

}




int getExam1Scores (int count, float Grade)
{
	

	for (rows = 0; rows < Num_Rows; rows++)
	{
		for (cols = 1; cols < 2; cols++)
			(
	cout << "Enter exam 1 grade for student " << rows+1 << ": ";
	cin >> NumStudents[rows][cols];
	Grade++;
	}
	cout << endl;
	return 0;
}

int getExam2Scores (int count, float Grade)
{
	
	cout << endl;
	for (rows = 0; rows < Num_Rows; rows++)
	{
for (cols = 2; cols < 3; cols++)
(
		cout "Enter exam 2 grade for student " << student+1 << ": ";
		cin >> NumStudents[rows][cols];
		Grade++;
	}
	cout << endl;

	return 0;
}

void calculateAverage 
{
	for (rows = 0; rows < Num_Rows; rows++)
	{
		for (cols = 3; cols <=3; cols++)
		{
		GradeAverage = ((Exam1Grade + Exam2Grade)/2);
	}
}

void display (int count)
{
	float TotalExam1Grade=0;
	float TotalExam2Grade=0.0, TotalAverage=0.0;

	float AvgExam1Grade, AvgExam2Grad, AvgAverage;

	cout << "\n\nSTUDENT" << "\t" << "Exam 2 " << "\t" << "Exam 3 " << "\t" << "Exam Average" << endl;
	for (int student = 0; student < count; student++)
	{
		cout << student+1 << "\t" << Exam1Grade[student] << "\t\t" << Exam2Grade[student] << "\t\t"<<
			GradeAverage(student) << "\t\t" << endl;

		TotalExam1Grade = TotalExam1Grade + Exam1Grade[student];
		TotalExam2Grade = TotalExam2Grade + Exam2Grade[student];
		TotalAverage = TotalAverage + GradeAverage[student];
	}

	cout << "\n\n Exam 1 Average      :" << AvgExam1Grade;
	cout << "\n Exam 2 Average       :" << AvgExam2Grade;
	cout << "\n Average for all students:" <<  AvgAverage;
}

Recommended Answers

All 2 Replies

Is that the exact code that you turned in? It's not that you're not calling the functions correctly from the main function; you're not calling them at all!

Did you write the functions, or were they given to you? I'm guessing it's the former. Why are you passing in "count" as a parameter to the getExam*Scores(...) functions but not using it? Also, i don't see where "Student" is defined. Does this code compile for you?

If I understand the problem correctly, I think your logic should go something like this:

For(each of 10 students, x)
{
read in exam score 1 and store it in examScoreArray[x][0]
read in exam score 2 and store it in examScoreArray[x][1]
}

For(each of 10 students, x)
{
studentAvg[x] = (examScoreArray[x][0] + examScoreArray[x][1]) / 2
}

You now have a 10x2 array of each student's two exam scores, examScoreArray[x][y] where x represents the student and y represents the exam number and the value held there is student x's score on exam y. You also have an array studentAvg[x], an array of each student x's average of two exam scores (which isn't really necessary, since the math can be easily done using the first array, but you seem to want this object). You can now do whatever math you want on these values and display them as you please.

It doesn't look like you have this basic logic down in your code. You should get that done, then work on pulling that code out, putting it in functions and calling it from main. For starters, try to get something that at least compiles, then work toward getting it to do what you want. For instance, even if this compiled:

for (cols = 3; cols <=3; cols++)
{
GradeAverage = ((Exam1Grade + Exam2Grade)/2);

It would execute only once. If you really wanted it to execute only once, you wouldn't need a for loop. If you want it to execute multiple times (presumably once per student), you need to figure out what loop arguments you need to have.

Is that the exact code that you turned in? It's not that you're not calling the functions correctly from the main function; you're not calling them at all!

Did you write the functions, or were they given to you? I'm guessing it's the former. Why are you passing in "count" as a parameter to the getExam*Scores(...) functions but not using it? Also, i don't see where "Student" is defined. Does this code compile for you?

If I understand the problem correctly, I think your logic should go something like this:

For(each of 10 students, x)
{
read in exam score 1 and store it in examScoreArray[x][0]
read in exam score 2 and store it in examScoreArray[x][1]
}

For(each of 10 students, x)
{
studentAvg[x] = (examScoreArray[x][0] + examScoreArray[x][1]) / 2
}

You now have a 10x2 array of each student's two exam scores, examScoreArray[x][y] where x represents the student and y represents the exam number and the value held there is student x's score on exam y. You also have an array studentAvg[x], an array of each student x's average of two exam scores (which isn't really necessary, since the math can be easily done using the first array, but you seem to want this object). You can now do whatever math you want on these values and display them as you please.

It doesn't look like you have this basic logic down in your code. You should get that done, then work on pulling that code out, putting it in functions and calling it from main. For starters, try to get something that at least compiles, then work toward getting it to do what you want. For instance, even if this compiled:

for (cols = 3; cols <=3; cols++)
{
GradeAverage = ((Exam1Grade + Exam2Grade)/2);

It would execute only once. If you really wanted it to execute only once, you wouldn't need a for loop. If you want it to execute multiple times (presumably once per student), you need to figure out what loop arguments you need to have.

Actually, I had looked over a lot of different array programs before I attempted this. I just became overwhelmed and exhausted so I did turn in what I had finished. There was much added and then much taken away several times. Thanks so much for replying to my request for help. I will take time to see if I can work this out more with what you have given me. I will let you know what happens.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.