Having trouble with simple grade averages/raised averages program

Somewhere along the line, the if/else statements nested inside the while loop are organized wrong.

This program should use a scanner to take the following inputs: the number of students that grades are entered for, the number of grades entered for each student, and the grades for each student. At the end, the program calculates the average grade for each student, and the raised average grade for each student (by dropping the lowest grade).

Here is the program below:

Re: Having trouble with simple grade averages/raised averages program

import java.util.Scanner;

public class Averages {

public static void main(String[] args) {

//variable declarations

int allStart = 0;

int allTotal = 0;

int start;

int studTotal = 0;

int studRaiseTotal = 0;

int numScores = 0;

int lowest = 0;

int score = 0;

Scanner testScan = new Scanner(System.in);

System.out.println("How many students are you entering scores for?"); //number of students

int students = testScan.nextInt();

System.out.println("How many scores do you need to enter for each student?");

numScores = testScan.nextInt();

//average for each student

double studRaiseAve;

double studNormAve;

//average for all students

double allAve;

double allRaiseAve;

while(allStart<students){

for(start = 0; start<numScores; start++)

{

System.out.println("Enter a score.");

lowest = testScan.nextInt();

score = lowest;

studTotal+=score;

if(start==-1){

testScan.close();

}

if(score<lowest);

{

studRaiseTotal = studTotal-lowest;

studRaiseAve = (double)(studRaiseTotal/(numScores-1));

System.out.println("Here is the student's scaled score.");

System.out.println(studRaiseAve);

}

studNormAve = (double)(studTotal/numScores);

System.out.println("Here is the student's average test scores.");

System.out.println(studNormAve);

if (studNormAve>=70){

System.out.println("This student passes.");

}

else{

System.out.println("This student fails.");

}

System.out.println("Here is the student's total test scores.");

System.out.println(studTotal);

}

start++;

allAve = (double)(allTotal/students);

System.out.println("Here is the class's average.");

System.out.println(allAve);

allTotal = studRaiseTotal;

allRaiseAve = (double)(allTotal/(students));

System.out.println("Here is the raised class average.");

System.out.println(allRaiseAve);

}

}

}

Re: Having trouble with simple grade averages/raised averages program

And here is what it returns:

How many students are you entering scores for?

2

How many scores do you need to enter for each student?

2

Enter a score.

90

Here is the student's scaled score.

0.0

Here is the student's average test scores.

45.0

This student fails.

Here is the student's total test scores.

90

...and it keeps returning that

Re: Having trouble with simple grade averages/raised averages program

First: delete while loop, cause it keeps returning "that".

Second: delete something like:

if(start==-1){

testScan.close();

}

from for loop, cause for loop have its own condition evaluation like bold one: for(start = 0; **start<numScores**; start++)

Re: Having trouble with simple grade averages/raised averages program

How many students are you entering scores for?

2

How many scores do you need to enter for each student?

3

Enter a score.

90

Here is the student's scaled score.

0.0

Here is the student's average test scores.

30.0

This student fails.

Here is the student's total test scores.

90

Enter a score.

80

Here is the student's scaled score.

45.0

Here is the student's average test scores.

56.0

This student fails.

Here is the student's total test scores.

170

Enter a score.

60

Here is the student's scaled score.

85.0

Here is the student's average test scores.

76.0

This student passes.

Here is the student's total test scores.

230

Here is the class's average.

0.0

Here is the raised class average.

85.0

Is what it's returning now. I'm going to keep tweaking this. Thanks!

Re: Having trouble with simple grade averages/raised averages program

Use "\n" in print() or println() method in order to get an extra empty line between block of the text.

Delete start++ in the bottom of foor loop body {...}, because it is already incremented in for loop each time after loop iteration, and before testing condition.

Re: Having trouble with simple grade averages/raised averages program

New version:

import java.util.Scanner;

public class Averages {

public static void main(String[] args) {

int allTotal = 0;

int start = 0;

int studTotal = 0;

int studRaiseTotal = 0;

int numScores = 0;

int lowest = 0;

int score = 0;

double studRaiseAve = 0;

double studNormAve = 0;

double allAve = 0;

double allRaiseAve = 0;

int i;

Scanner testScan = new Scanner(System.in);

System.out.println("How many students are you entering scores for?"); //number of students

int students = testScan.nextInt();

System.out.println("How many scores do you need to enter for each student?");

numScores = testScan.nextInt();

for(start = 0; start<numScores; start++)

{

for(i = 0; i < students; i++){

int n = i+1;

System.out.println("Enter a score for student number "+n);

lowest = testScan.nextInt();

score = lowest;

studTotal+=score;

if((score<lowest)&&numScores>1);

{

studRaiseTotal = studTotal-lowest;

studRaiseAve = (double)(studRaiseTotal/(numScores-1));

}

if((score<lowest)&&numScores==1){

studRaiseTotal = studTotal;

studRaiseAve = (double) (studRaiseTotal/numScores);

}

}

System.out.println("Here is the student's scaled score.");

System.out.println(studRaiseAve);

studNormAve = (double)(studTotal/numScores);

System.out.println("Here is the student's average test scores.");

System.out.println(studNormAve);

if (studNormAve>=70){

System.out.println("This student passes.");

}

else{

System.out.println("This student fails.");

}

System.out.println("Here is the student's total test scores.");

System.out.println(studTotal);

}

allAve = (double)(allTotal/students);

System.out.println("Here is the class's average.");

System.out.println(allAve);

allTotal = studRaiseTotal;

allRaiseAve = (double)(allTotal/(students));

System.out.println("Here is the raised class average.");

System.out.println(allRaiseAve);

}

}

Re: Having trouble with simple grade averages/raised averages program

And what it returns:

How many students are you entering scores for?

2

How many scores do you need to enter for each student?

2

Enter a score for student number 1

90

Enter a score for student number 2

96

Here is the student's scaled score.

90.0

Here is the student's average test scores.

93.0

This student passes.

Here is the student's total test scores.

186

Enter a score for student number 1

2

Enter a score for student number 2

2

Here is the student's scaled score.

188.0

Here is the student's average test scores.

95.0

This student passes.

Here is the student's total test scores.

190

Here is the class's average.

0.0

Here is the raised class average.

94.0