# Thread: need help with function

1. ## need help with function

From the code below I need to add a function to calculate and print the top score for each student, any input?void main(void){

#include <iostream.h>
#define size 4

void main(void){

const int exam = 3;
const int student= 4;
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];
}

}

}

2. for(int i=0; i<student; i++) //erase the word register
{
cout<<"Enter first name for student "<<i+1<<": ";
cin>>first_name[i];
cout<<"Enter last name for student "<<i+1<<": ";
cin>>last_name[i];

//remove the following two lines
//}
//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];

//adjust the } as needed.

3. Initialise a variable containing the max score to zero. Loop through the students scores, on each iteration compare the max score to the score held in the array. If the array score is higher, update the max score with this value. At the end you'll have the max score.

Popular pages Recent additions