Hi
I need some help creating a function that will check if each element in the array "contestantScore[]" which is defined from user input, is less or more than the variable "average" which is defined from the sum of the array "contestantScore[] / contestantScore.length" and then returns either the String "above" or "below"
I have racked my brain now for hours trying to create a function that will do this, going over course material etc....
I'm not asking anyone to write the code but a point in the right direction would great.
I'll put my code up so far so you can see what I'm doing : )
The function I have up the top of my code doesn't work and returns errors...
"average cannot be resolved into a variable"
"contestantScore cannot be resolved into a variable"
Sorry about the formatting, it looked better in eclipse : (
import java.util.Scanner;
public class pracQ3_2
{
//I need a function that will return the String "above" or "below" if each element in the array is less or more than the average.
public String aboveOrBelow ()
{
String above;
String below;
if (contestantScore < average)
{
return below;
}
else
{
return above;
}
}
public static void main(String[] args)
{
int [] contestantNum;
double [] contestantScore;
int index;
double average;
Scanner keyboard = new Scanner(System.in);
contestantNum = new int [10];
contestantNum[0] = 1;
contestantNum[1] = 2;
contestantNum[2] = 3;
contestantNum[3] = 4;
contestantNum[4] = 5;
contestantNum[5] = 6;
contestantNum[6] = 7;
contestantNum[7] = 8;
contestantNum[8] = 9;
contestantNum[9] = 10;
contestantScore = new double [10];
for (index = 0; index < 10; index = index + 1)
{
System.out.print("Enter score for contestant number " + contestantNum[index] + ": ");
contestantScore[index] = keyboard.nextDouble();
}
System.out.println();
for (index = 0; index < 10; index = index + 1)
{
System.out.println("Contestant Number " + contestantNum[index] + " rated " + contestantScore[index] + " out of 10");
}
average = (contestantScore[0] + contestantScore[1] + contestantScore[2] + contestantScore[3] + contestantScore[4] + contestantScore[5] + contestantScore[6] + contestantScore[7] + contestantScore[8] + contestantScore[9]) / contestantScore.length;
System.out.print(average);
}
}