Hey. Um... I'm having problems with one of my hw assignments (actually 2, but if you help me solve this one, you'll have helped me solve the other one.) and I really need help with it. I've asked the professor, but his suggestions are not helping me. I'm using Eclipse for my assignment, if that helps anybody.
Question: Write a program that reads an unspecified number of scores ( scores are between 0 and 100 inclusive) into an array and determines how many scores are above or equal to the average and how many scores are below the average. Do not allow scores outside the range to be entered. Assume the maximum number of scores is 30. Do not allow more than 30 scores to be entered. Enter a negative number to signify the end of the input. Please also print the average of the scores and the number of scores that were input.
My Code:
import java.util.Scanner;
public class Scores {
public static void main(String[] args)
{
Scanner scan = new Scanner (System.in);
double total = 0;
int aboveAverage = 0;
int average = 0;
int belowAverage = 0;
double mean; double score;
int count = 0;
double array[] = new double[31];
System.out.print("Please enter a score. Enter up to thirty scores. Enter a negative number to quit.");
score = scan.nextDouble();
for (int i = 0; i < array.length; i++)
while (score >= 0 && score <= 100 && count <= 30)
{
array[count] = score;
count++;
System.out.print("Please enter a score. Enter up to thirty scores Enter a negative number to quit.");
score = scan.nextDouble();
}
for (int i = 0; i < array.length; i++)
{
array[(int) score]++;
score = scan.nextDouble();
}
for (int i = 0; i < array.length; i++)
{
array[i] = scan.nextInt();
total = array[i];
}
mean = total / count;
for (int i = 0; i < array.length; i++)
{
if (score >= 80)
aboveAverage++;
else
{
if (score >= 70 && score <= 79)
average++;
else
{
if (score <= 69)
belowAverage++;
}
}
}
System.out.println("Number of scores input: " + count);
System.out.println("Above Average count: " + aboveAverage); System.out.println("Average count: " + average);
System.out.println("Under Average count: " + belowAverage); System.out.println("Average of scores: " + mean);
}
}
Problems: I receive an error when I input a negative number. When I ignore the negative number and just go on until the list is full, nothing is calculated! It all said "yadayada equals zero" and then after making adjustments, it won't even say "yadayada" anymore! Any help would be appreciated!
Question: Write a program that reads an unspecified number of scores ( scores are between 0 and 100 inclusive) into an array and determines how many scores are above or equal to the average and how many scores are below the average. Do not allow scores outside the range to be entered. Assume the maximum number of scores is 30. Do not allow more than 30 scores to be entered. Enter a negative number to signify the end of the input. Please also print the average of the scores and the number of scores that were input.
My Code:
import java.util.Scanner;
public class Scores {
public static void main(String[] args)
{
Scanner scan = new Scanner (System.in);
double total = 0;
int aboveAverage = 0;
int average = 0;
int belowAverage = 0;
double mean; double score;
int count = 0;
double array[] = new double[31];
System.out.print("Please enter a score. Enter up to thirty scores. Enter a negative number to quit.");
score = scan.nextDouble();
for (int i = 0; i < array.length; i++)
while (score >= 0 && score <= 100 && count <= 30)
{
array[count] = score;
count++;
System.out.print("Please enter a score. Enter up to thirty scores Enter a negative number to quit.");
score = scan.nextDouble();
}
for (int i = 0; i < array.length; i++)
{
array[(int) score]++;
score = scan.nextDouble();
}
for (int i = 0; i < array.length; i++)
{
array[i] = scan.nextInt();
total = array[i];
}
mean = total / count;
for (int i = 0; i < array.length; i++)
{
if (score >= 80)
aboveAverage++;
else
{
if (score >= 70 && score <= 79)
average++;
else
{
if (score <= 69)
belowAverage++;
}
}
}
System.out.println("Number of scores input: " + count);
System.out.println("Above Average count: " + aboveAverage); System.out.println("Average count: " + average);
System.out.println("Under Average count: " + belowAverage); System.out.println("Average of scores: " + mean);
}
}
Problems: I receive an error when I input a negative number. When I ignore the negative number and just go on until the list is full, nothing is calculated! It all said "yadayada equals zero" and then after making adjustments, it won't even say "yadayada" anymore! Any help would be appreciated!
Comment