Thread: need help with function

  1. #1
    Unregistered
    Guest

    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. #2
    Unregistered
    Guest
    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. #3
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    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 subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM