Results 1 to 8 of 8
 01192012, 08:22 PM #1
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:Last edited by LogicalOutlier; 01192012 at 08:39 PM.
 01192012, 08:39 PM #2
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 = studTotallowest;
studRaiseAve = (double)(studRaiseTotal/(numScores1));
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);
}
}
}
 01192012, 08:40 PM #3
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
 01192012, 11:38 PM #4Senior Member
 Join Date
 Jan 2012
 Posts
 210
 Rep Power
 3
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++)
 01202012, 12:01 AM #5
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!Last edited by LogicalOutlier; 01202012 at 12:04 AM.
 01202012, 12:42 AM #6Senior Member
 Join Date
 Jan 2012
 Posts
 210
 Rep Power
 3
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.
 01202012, 09:42 PM #7
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 = studTotallowest;
studRaiseAve = (double)(studRaiseTotal/(numScores1));
}
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);
}
}
 01202012, 09:44 PM #8
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
Similar Threads

Looping over averages in an int[][] array
By adventurerOK in forum Advanced JavaReplies: 1Last Post: 09282011, 09:16 PM 
Beginner Loops for averages
By mobosecomin in forum New To JavaReplies: 6Last Post: 10172010, 09:17 PM 
Problem with Sums and Averages in Sales Report
By DavidEvans in forum New To JavaReplies: 9Last Post: 04212010, 08:57 PM 
Averages of user inputed values (Need Help)
By Zebra in forum New To JavaReplies: 2Last Post: 04162008, 01:51 PM 
[SOLVED] Integers (averages and remainders)...need help
By Zebra in forum New To JavaReplies: 4Last Post: 04162008, 01:26 PM
Bookmarks