Hi all, I'm having a bit of trouble with a homework assignment. I'm supposed to write a program that calculates the average of a number of tests scores while dropping the lowest. I'm stuck on a G++ compiler error and I've not made any progress on it. Here's my code:
Code:
#include <iostream>#include <iomanip>
using namespace std;
void start();
void getScore(int&);
void calcAvg(int scores[5]);
int findLowest(int scores[5]);
char run;
int main()
{
int scores;
start();
while (run == 'Y' || run == 'y')
{
getScore(scores);
calcAvg(scores);
start();
}
return 0;
}
// fucntion to change value of run variable, allowing user to run again or quit
void start()
{
cout << "Type Y to run program, Q to quit." << endl;
cin >> run;
cin.ignore();
}
// function to get scores from user input
void getScore()
{
int size = 5;
double scores[5];
cout << "Please enter test scores." << endl;
for ( int i=0 ; i<5 ; i++ )
{
cout << "Enter score " << ( i + 1 ) << " : ";
cin >> scores[i];
// check to make sure the score is valid - find out if this works on arrays
while (scores[i] < 0 || scores[i] > 100)
{
cout << "Please enter a vaild score between 0 and 100: ";
cin >> scores[i];
}
}
}
// fucntion to find the lowest score entered via array loop
int findLowest(int scores[5])
{
int lowest = 0; // starts with the first index of the array
for (int i=1 ; i<5 ; ++i) // loop to find lowest score by through comparison
{
if (scores[i] < scores[lowest])
{
lowest=i;
}
}
return lowest; // return the lowest found value
}
// function to calculate the average of the scores, excluding the lowest
void calcAvg(int scores[5])
{
double average=0;
int sum=0; // not sure about this
for (int i=0 ; i<5 ; ++i)
{
sum+=scores[i];
}
average-=scores[findLowest(scores)]; // not sure about sytax here, check
average/=4;
}
And here's the error:
Code:
avg_scoredrop.cpp: In function ‘int main()’:
avg_scoredrop.cpp:38:17: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]
avg_scoredrop.cpp:25:6: error: initializing argument 1 of ‘void calcAvg(int*)’ [-fpermissive]
I've found a few links via google about this, but I haven't been able to determine what I'm doing wrong. I'm fairly sure the problem is in my function prototypes. Any advice would be greatly appreciated! Furthermore, general critiques of my code would be great too!