Please send questions to
st10@humboldt.edu .
/*--------------------------------------------------
File: minGrade.cpp
Name: Sharon M. Tuttle
last modified: 5-3-05
Contract: minGrade : double[] int -> double
Purpose: return the smallest grade amongst the
first size grades in array grades.
(return 0 if size is 0 or less!)
Examples: for double grades[10] = {76.5, 88.0, 99.6, 66,
43.0, 93.2, 73.0, 72.0,
74.0, 95};
minGrade(grades, 10) == 43.0
--------------------------------------------------*/
#include <iostream>
#include <cmath>
using namespace std;
double minGrade(const double grades[], int size)
{
double minGradeSoFar;
// for array size of 0 or less, just stop now!
if (size == 0)
{
return 0.0;
}
// IF reach here, then, there ARE some grades to
// check;
// first is smallest seen so far...
minGradeSoFar = grades[0];
// ...now compare the REST in grades, to see if
// any other is smaller:
for (int i=1; i < size; i++)
{
if (grades[i] < minGradeSoFar)
{
minGradeSoFar = grades[i];
}
}
return minGradeSoFar;
}