My for loop never ends, I don't understand.
I'm trying to get the next line of code after that statement to output but it's not working. I appreaciate any help.
for (int count = 0; count < NUM_QUESTIONS; count++)
{
//Generate two random singal digit numbers
num1 = gen.nextInt(RANGE);
num2 = gen.nextInt(RANGE);
//Display the equation and input user answer
System.out.print("\n\n\n\n\t\t\t\t\t\t\t\t" +
num1 + " + " + num2 + " = ");
answer = Keyboard.readInt();
//IF (answer is correct)
if (answer == num1 + num2)
{
// Display Correct
System.out.println ( " CORRECT " );
//Add 1 to number correct
numCorrect++;
}
// ELSE Display answer is Incorrect
else
{
System.out.println ( " INCORRECT " );
}
}
I'm trying to get the next line of code after that statement to output but it's not working. I appreaciate any help.
public static void main (String [] args)
{
import java.util.Random;
public class MathTest
{
//local constants
final int RANGE = 10; //# of diff values to create
final int NUM_QUESTIONS = 5;
final int QUIT = 2;
//local variables
int num1; // 1st number
int num2; // 2nd number
int answer; // answer to the addition problem
int userSelection; // user selects to take test or to quit
int numCorrect; // number of correct answers
int testScore; // test score of user in percentage
Random gen = new Random(); // Random class to generate random numbers
Library myLib = new Library ();
//Display test menu and input user choice
System.out.print("\n\n Simple Math Tests Made Easy\n\n" +
" 1. Take a Test\n" +
" 2. Quit\n\n" +
" Enter Choice: ");
userSelection = Keyboard.readInt();
//WHILE (user selection is take test)
while(userSelection != QUIT)
{
//Clear the screen
myLib.clrscr();
//Init number correct to 0
numCorrect = 0;
//FOR (Each of the 5 questions)
for (int count = 0; count < NUM_QUESTIONS; count++)
{
//Generate two random singal digit numbers
num1 = gen.nextInt(RANGE);
num2 = gen.nextInt(RANGE);
//Display the equation and input user answer
System.out.print("\n\n\n\n\t\t\t\t\t\t\t\t" +
num1 + " + " + num2 + " = ");
answer = Keyboard.readInt();
//IF (answer is correct)
if (answer == num1 + num2)
{
// Display Correct
System.out.println ( " CORRECT " );
//Add 1 to number correct
numCorrect++;
}
// ELSE Display answer is Incorrect
else
{
System.out.println ( " INCORRECT " );
}
}
System.out.print ( " Hey " );
}
} //end main method
} //end MathTest