Please don't use all caps in your posts and post your code between [ code] tags. Thank you.
First thing, there is no need to duplicate your code that prompts the user with the quiz questions. It defeats the purpose of a loop.
Lets start by establishing your inner loop, since you have that working correctly already.
CODE
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!";
number_right++;
JOptionPane.showMessageDialog(null, message.toUpperCase());
}
else
{
message = "Wrong!";
JOptionPane.showMessageDialog(null, message.toUpperCase());
}
++counter;
}
Now this code needs to be wrapped in a second loop. In this case I would use a Do/While loop, although a While loop will work equally well. I just prefer not to have to ask the same question twice in code when you only have to do it once with a Do/While loop.
CODE
do
{
//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!";
number_right++;
JOptionPane.showMessageDialog(null, message.toUpperCase());
}
else
{
message = "Wrong!";
JOptionPane.showMessageDialog(null, message.toUpperCase());
}
++counter;
}
number_total = number;
JOptionPane.showMessageDialog(null, "You correctly answered "+number_right+" out of "+number_total+" questions correctly. \nYour percentage is: "+(double)number_right/(double)number_total+"%");
input = JOptionPane.showInputDialog("Do you want to take the quiz again?");
}while(input.toUpperCase().equals("YES"));
To test the condition of a string variable you cannot simply use the == for the equality check. You must use the String method
equals to compare strings. But because the user can enter the word several different ways, meaning with caps or without, you will need to convert it to upper or lowercase or test for all possibilities. It simpler to just convert to one or the other and compare one condition.
CODE
while(input.toUpperCase().equals("YES"));
So in this bit of code we are stacking methods to get this done in one line. Input is your string variable, which is then converted to uppercase, and the last step is to use the equals method to test the condition.
The last step that needs to be taken care of to get this working properly is that you have a couple of variables that are keeping track of things. So you will need to reset those variables before starting a new game.
When all is said and done you will end up with code like this:
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 = 0; //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
do
{
//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!";
number_right++;
JOptionPane.showMessageDialog(null, message.toUpperCase());
}
else
{
message = "Wrong!";
JOptionPane.showMessageDialog(null, message.toUpperCase());
}
++counter;
}
number_total = number;
JOptionPane.showMessageDialog(null, "You correctly answered "+number_right+" out of "+number_total+" questions correctly. \nYour percentage is: "+(double)number_right/(double)number_total+"%");
input = JOptionPane.showInputDialog("Do you want to take the quiz again?");
counter = 1;
number_right = 0;
}while(input.toUpperCase().equals("YES"));
System.exit(0);
}
}