#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
//change the variable size to modify the amount of grades desired
constint size = 5;
int array[size];
int lowest = 101;
int total = 0;
double average;
int i = 0;
//loop through the array
for (i = 0; i < size; i++)
{
//get inputs
cout << "\nPlease enter grade " << i + 1 << ": ";
cin >> array[i];
//check that value entered is between 0 and 100
while (array[i] < 0 || array[i] >100)
{
cout << "Wrong input. Please enter a value between 0 and 100 only." << endl;
cout << "\nPlease Reenter grade " << i + 1 << " : ";
cin >> array[i];
}
}
//pass the array to function getLowestGrade() instead, get the value as a return
lowest = getLowestGrade(array);
//loop through the array
for (i = 0; i < size; i++)
{
//if the value of the array element isn't the lowest then we'll add it to the total(because you want to drop the lowest value)
if (array[i] != lowest)
{
total = total + array[i];
}
}
//then take the total and divide it by the total sample (size minus one because we ditched the lowest grade)
average = (total / (size - 1));
//print the average
cout << average;
//pause
system("pause");
}
int getLowestGrade(int array[])
{
int lowest = 101;
//loop through the array
for (i = 0; i < size; i++)
{
while (array[i] < lowest)
{
lowest = array[i];
}
}
return lowest;
}
getLowestGrade has a variable size that doesn't exist for it and i isn't initialized either. Also while loop?
Corrected version:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int getLowestGrade(int array[], int size)
{
int lowest = array[0];
//loop through the array
for (int i = 1; i < size; i++)
{
if(array[i] < lowest)
{
lowest = array[i];
}
}
return lowest;
}
main needs to return 0;
After that you will have to make some minor corrections in your main()