# Using a function to calculate top score

• 02-26-2002
Unregistered
Using a function to calculate top score
Hi,
I need to ask the user for first name, last name, and the score of 3 exams and then call a function "Top_Score" which is passed the arrays and prints out each student name along with each student's top exam score in the format:
Student First Name: Student Last Name: Top Score:

This is what I have done so far.

#include <iostream.h>
#define size 10
void Top_scores(char [][], char[][], int [][]);

void main(void){

const int exam = 3;
const int student= 10;
char last_name[size][8];
char first_name[size][8];
char first, last;
int scores[student][exam];
int j=0;

for(register int i=0; i<student; i++)
{
cout<<"Enter first name for student "<<i+1<<": ";
cin>>first_name[i];
cout<<"Enter last name for student "<<i+1<<": ";
cin>>last_name[i];
}
for(i=0;i<student; i++){
for( j=0;j<exam; j++){

cout<<"Enter score #"<<j+1<<"for "<<first_name[i] <<" "<<last_name[i]<<": ";
cin>>scores[i][j];
}

Top_scores(first_name,last_name,exam);
}

void Top_scores(char first[][],char last[][], int scores[][])
{

int top=0;
top=scores[0][0]
for(int i=0; i<10;i++){
for(j=0;j<3;j++)
if(scores[i][j]>top
top=scores[i][j];
}
for(i=0;i<10;i++)
cout<<"first name "<<first_name[i]<<"last name "<<last_name[i]<<"Top score "<<top<<"\n";
}
}

}