Making a grade book that will work for one student, it take student's name as input. Then they are asked to input grades into three categories: Homework, Quizzes, and Tests. The grades in each category will each be averaged and at the end, the formula "Final Average = 0.25*HomeworkAvg + 0.25QuizAvg + 0.50TestAvg = 65
Everything is working properly BUT -1 is not ending the process! It's frustrating!
import java.util.Scanner;
public class Assignment3
{
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );
int homeworkGrades;
int quizGrades;
int testGrades;
int choice;
int total;
double average;
String name;
total = 0;
homeworkGrades = 0;
System.out.println( "Enter 1 or 2: \n 1 - Average grades \n 2 - Quit" );
choice = input.nextInt();
if ( choice == 1 ) {
System.out.println( "Enter the students name" );
name = input.next();
System.out.println( " What would you like to do? \n 1 - Homework grades \n 2 - Quiz grades \n 3 - Test grades " );
choice = input.nextInt();
{
while ( choice == 1 ) {
System.out.println( "Enter a homework grade. Press -1 when finished" );
homeworkGrades += input.nextInt();
if ( homeworkGrades != -1 ) //it's something going on right here :s
if ( homeworkGrades == -1 )
System.out.println("Total for homework grades is " + homeworkGrades );
}
}
}
else if ( choice == 2 ) {
System.out.println( "Exiting program" );
}
else {
System.out.println( "Invalid response, exiting program." );
}
}
}
90, 86, 50, -1. homeworkGrades is now 225, not -1 like you think.