I completed most of the functions and it compiles but need help with two.Can someone help me with the uniqueScore function which is suppose to print test scores that only appears once and the differenceScore function which is suppose to print the difference between the largest and smallest score.

#include <iostream>
using namespace std;
#include <fstream>
void loadArray ( int intscores[], int numScores );
void printScores ( int intscores[], int numScores);
void computeAverage ( int scores, int numScores, double & average);
void greaterAverage ( int intscores [], int numScores, double & average);
void uniqueScores ( int scores, int numScores);
void largestScore ( int intscores[], int numScores, double largest);
void smallestScore ( int intscores[], int numScores, double smallest);
void differenceScore ( int scores, int numScores);


int main ()
{
    //declare variables
    int scores;
    int numScores;
    double largest;
    double smallest;
    double average;

}

//loads data from file
void loadArray(int intscores[], int size)
{
     ifstream infile;
     infile.open("scores.dat");
     size=0;
     while (!infile.eof() )
     {
           infile >> intscores[size];
           size++;
     }
     infile.close();

}
//prints scores 
 void printScores (int intscores[], int numScores)
{
      cout << "printing scores" <<endl;
      for (int i = 0; i < numScores; i++)
      cout << intscores[i] <<endl;
} 
//computes the average   
void computeAverage ( int scores, int numScores, double & average)
{
     average = (scores)/numScores;
}
//prints all scores greater than the average
void greaterAverage (int intscores[], int numScores, double & average)
{
     cout << "printing scores greater than the average score" <<endl;
     for (int i = 0; i < numScores; i++)
     if (intscores[i] > average)
     cout << intscores[i] <<endl;

}   
//the unique test scores that appears only once
void uniqueScores (int scores, int numScores)
{
}
//prints the largest score
void largestScore (int intscores[], int numScores, double largest)
{
     cout << "printing the largest score" <<endl;
     largest = 0;
     for (int i = 0; i < numScores; i++)
     if (intscores[i] > largest)
     largest = intscores[i];
}
//prints the smallest score
void smallestScore (int intscores[], int numScores, double smallest)
{
     cout << "printing the smallest score" <<endl;
     smallest = 0;
     for (int i = 0; i < numScores; i++)
     if (intscores[i] < smallest)
     smallest = intscores[i];

}
//the difference between the largest and smallest score
void differenceScore (int scores, int numScores)
{
}

code:

#include <iostream>
using namespace std;
#include <fstream>
void loadArray ( int intscores[], int numScores );
void printScores ( int intscores[], int numScores);
void computeAverage ( int scores, int numScores, double & average);
void greaterAverage ( int intscores [], int numScores, double & average);
void uniqueScores ( int scores, int numScores);
void largestScore ( int intscores[], int numScores, double largest);
void smallestScore ( int intscores[], int numScores, double smallest);
void differenceScore ( int scores, int numScores);


int main ()
{
    //declare variables
    int scores;
    int numScores;
    double largest;
    double smallest;
    double average;

}

//loads data from file
void loadArray(int intscores[], int size)
{
     ifstream infile;
     infile.open("scores.dat");
     size=0;
     while (!infile.eof() )
     {
           infile >> intscores[size];
           size++;
     }
     infile.close();

}
//prints scores 
 void printScores (int intscores[], int numScores)
{
      cout << "printing scores" <<endl;
      for (int i = 0; i < numScores; i++)
      cout << intscores[i] <<endl;
} 
//computes the average   
void computeAverage ( int scores, int numScores, double & average)
{
     average = (scores)/numScores;
}
//prints all scores greater than the average
void greaterAverage (int intscores[], int numScores, double & average)
{
     cout << "printing scores greater than the average score" <<endl;
     for (int i = 0; i < numScores; i++)
     if (intscores[i] > average)
     cout << intscores[i] <<endl;

}   
//the unique test scores that appears only once
void uniqueScores (int scores, int numScores)
{
}
//prints the largest score
void largestScore (int intscores[], int numScores, double largest)
{
     cout << "printing the largest score" <<endl;
     largest = 0;
     for (int i = 0; i < numScores; i++)
     if (intscores[i] > largest)
     largest = intscores[i];
}
//prints the smallest score
void smallestScore (int intscores[], int numScores, double smallest)
{
     cout << "printing the smallest score" <<endl;
     smallest = 0;
     for (int i = 0; i < numScores; i++)
     if (intscores[i] < smallest)
     smallest = intscores[i];

}
//the difference between the largest and smallest score
void differenceScore (int scores, int numScores)
{
}

Edited 4 Years Ago by mike_2000_17: Fixed formatting

First off I would prefer if you just post your code and not a code snippit as well.

Second-- I would like an atempt at the two functions. So instead of helping you directly with them, I am going to comment on your other functions..
Let me start with :

largestScore
Ok err.. it doesn't print anything:
Second the variable largets is not actually set externally.
E.g. try this in main

int main()
{
   int scores[]={5,6,7,8};
   double large(3.0);
   largestScore(scores,4,large);
   // SURPRISE: this prints 3.0
   std::cout<<"Large == "<<large<<std::endl; 
}

You worry me that you haven't tested anything you have written.
you additionaly convert between integer and double. Your also would have real problems with this input: int score[]={-3,-4}; Initialize your largest/smallest values with the FIRST value, not with zero or some other arbitory number.

Finally: You have made this mistake:

int A(5);
int B(7);
std::cout<<"A/B == "<<A/B<<std::endl;
// this prints ZERO.

Because this is integer division.

PLEASE test your code. ALWAYS regardless of what you think it does.

This article has been dead for over six months. Start a new discussion instead.