CODE
//Importing the neccesary commands
import javax.swing.JOptionPane;
import java.util.Random;
public class Jay2
{
public static void main(String [] args)
{
int ques1; //First random number
int ques2; // Second random number
int number = 0; //How many questions input
int counter = 1; //while counter
int ques_sum; //sum of the two random numbers
int response; //your answer
int number_right = 1; //number of questions answered correctly
int number_total = 0; //number of questions you wanted
String input; //Your input for the two numbers
String message; //Correct of Wrong massages
Random questions = new Random(); //Random number selector
//Asking how many questions
input = JOptionPane.showInputDialog("Welcome to Jay's simple addition quiz! \n\nHow many questions would you like?");
number = Integer.parseInt(input);
while(counter <= number)
{
ques1 = (Math.abs(questions.nextInt())%20)+1;
ques2 = (Math.abs(questions.nextInt())%20)+1;
ques_sum = (ques1+ques2);
input = JOptionPane.showInputDialog(ques1+ "+" +ques2);
response = Integer.parseInt(input);
if(response == (ques_sum))
{
message = "Correct!";
JOptionPane.showMessageDialog(null, message.toUpperCase());
}
else
{
message = "Wrong!";
JOptionPane.showMessageDialog(null, message.toUpperCase());
}
++counter;
}
number_right = (response==ques_sum); // THIS IS WHERE I AM GETTING ERRORS, I DONT KNOW WHY
number_total = number;
JOptionPane.showMessageDialog(null, "You correctly answered "+number_right+" out of "+number_total+" questions correctly. \nYour percentage is: "+number_right/number_total+"%");
System.exit(0);
}
}