help with computing average with arrays and functions

I'm having trouble writing code. The purpose of the lab is to gain experience with passing arrays in the parameter list. The user is asked to enter the n scores of N# of students (both arrays). The problem I'm having is how do I pass the value of lowest to the function computeaverage. The parameters cannot be deviated. The program is to drop the lowest score and compute the average. Please help.....


#include <iostream>
using namespace std;



float ComputeAverage(int, float []);
bool MoreStudents();
int GetNumberExams();
void GetExamScores(int, int, float[]);


int main()
{
float CourseGrades[35]; // Array of computed exam averages.
int NoStudents = 0; // Count of the number of students.
float ExamScores[10]; // Array of exam grades for a student.
int NoExams = 0; // Number of exams for the current course.

NoExams = GetNumberExams(); // Access the number of exams per student.

// Each time through this loop, the exam grades for one more student
// will be entered and processed.
do {
// Enter the exam grades for the current student. The grades
// are placed in the array ExamScores.
GetExamScores(NoExams, NoStudents, ExamScores);

// Compute the average score, after dropping the lowest.
// The average is placed into the next element of the
// CourseGrades array.
CourseGrades[NoStudents] = ComputeAverage(NoExams, ExamScores);

NoStudents++; // Increment the student count.

} while (MoreStudents()==true); // Loop as long as there are more students.

// Each time through this loop, the average grade for another
// student is output.
for (int i = 0; i < NoStudents; i++)
{
cout << "\nStudent " << i + 1 << ": ";
cout << CourseGrades[i];
}

cout << endl; // Flush the console buffer.

return 0; // Exit the program.
}

int GetNumberExams(int number)
{
cout<<"How many exams are there for this course: ";
cin>>number;
return number;
}

void GetExamScores(int nostud, int noex, float exscore[])
{
int n=0;
float sum=0.0f;
float lowest=100.0f;
cout<<"For student "<<nostud+1;
do
{
cout<<"Enter exam score "<<n+1<<":";
cin>>exscore[n++];
sum+=exscore[n];
if (exscore[n]<lowest);
lowest=exscore[n];
} while(n<=noex);
}

bool MoreStudents(bool response)
{
char resp;
cout<<"Are there more students?\nEnter a Y or N: --------> ";
cin>>resp;
resp=toupper(resp);
if (resp='Y')
response=true;
else
response=false;
return response;
}


float ComputeAverage(int NoExams, float ExamScores[])
{
return (sum-lowest)/(NoExams-1);


}
Last edited on
closed account (N36fSL3A)
Go through. Check if the first element is larger or smaller. If it's smaller, set it to a temp value. check that temp value with the 3 element, if the third element's larger, set that as the temp value, else keep that past value, etc.
I've update the code. Is the location of sum correct? do I want it in computeaverage or getscores? If it's in getscores how do I pass a value to computeaverage (void function)?

#include <iostream>
using namespace std;



float ComputeAverage(int, float []);
bool MoreStudents();
int GetNumberExams();
void GetExamScores(int, int, float[]);


int main()
{
float CourseGrades[35]; // Array of computed exam averages.
int NoStudents = 0; // Count of the number of students.
float ExamScores[10]; // Array of exam grades for a student.
int NoExams = 0; // Number of exams for the current course.

NoExams = GetNumberExams(); // Access the number of exams per student.

// Each time through this loop, the exam grades for one more student
// will be entered and processed.
do {
// Enter the exam grades for the current student. The grades
// are placed in the array ExamScores.
GetExamScores(NoExams, NoStudents, ExamScores);

// Compute the average score, after dropping the lowest.
// The average is placed into the next element of the
// CourseGrades array.
CourseGrades[NoStudents] = ComputeAverage(NoExams, ExamScores);

NoStudents++; // Increment the student count.

} while (MoreStudents()==true); // Loop as long as there are more students.

// Each time through this loop, the average grade for another
// student is output.
for (int i = 0; i < NoStudents; i++)
{
cout << "\nStudent " << i + 1 << ": ";
cout << CourseGrades[i];
}

cout << endl; // Flush the console buffer.
system("pause");
return 0; // Exit the program.
}

int GetNumberExams()
{
int number;
cout<<"How many exams are there for this course: ";
cin>>number;



return number;
}

void GetExamScores(int noex, int nostud, float exscore[])
{
int n=0;
cout<<"For student "<<nostud+1<<"\n";
do
{
cout<<"\tEnter exam score "<<n+1<<":";
cin>>exscore[n++];
}
while(n<noex);

}

bool MoreStudents()
{
char resp;
bool response;
cout<<"Are there more students?\nEnter a Y or N: --------> ";
cin>>resp;
resp=toupper(resp);
if (resp=='Y')
response=true;
else
response=false;
return response;
}


float ComputeAverage(int NoExams, float ExamScores[])
{
int n=0;
float sum=0.0f;
float lowest=100.0f;
sum+=ExamScores[n];
if (ExamScores[n]<lowest);
lowest=ExamScores[n];
return (sum-lowest)/(NoExams-1);
}

please any help would be appreciated.....
Topic archived. No new replies allowed.