while ( choice != -1 ) {
System.out.println( "Enter a homework grade. Press -1 when finished" );
homework = dylan.nextInt();
}
This loop will never exit, because the user’s entry is put into homework
, but you’re testing choice
in the while loop.
The fix:
while ( homework != -1 ) {
System.out.println( "Enter a homework grade. Press -1 when finished" );
homework = dylan.nextInt();
}
Also note that, as stated by @Jack and others, homework
(which should really be named something like iTotalGrades
) should be accumulating the input, not just overwriting with the next value. It also should not add the -1
(thanks again to @Jack), which is not a grade at all. Meaning this is my recommendation:
while (iInput != -1 ) {
System.out.println( "Enter a homework grade. Press -1 when finished" );
iInput = dylan.nextInt();
if(iInput != -1)
iTotalGrades += iInput;
}
}
There are other problems, as noted by others, but these two are big ones.
5
solved User-enter values are not being stored properly