I dont know where i need to put a loop at in my code to ask a new addition problem.
This program is for some kids between the ages of 4-7. Please help!!!!
import java.util.Random;
import javax.swing.JOptionPane;
public class Adding_Problems{
public static void main(String [] args) {
//Declare
Random generator = new Random();
int num1;
int num2;
int answer;
int guess1;
String choice;
boolean shouldLoopEnd = false;//boolean variable to determine if the loop should end
//Input
num1 = generator.nextInt(50); //Gets random num1
num2 = generator.nextInt(50); //Gets Random num2
//infinite loop begins...
while (true)
{
choice=JOptionPane.showInputDialog ("what is " + num1 + "+" + num2);
//Process
guess1 = Integer.parseInt(choice);
answer = (num1 + num2);
//Output
if (guess1 == answer){ //check to see if the guess is correct
shouldLoopEnd = true;}
if(shouldLoopEnd == true)
{ //Begin if bracket
JOptionPane.showMessageDialog (null, "Correct!");
break; // break loop
} //End if Brackets
else
{
//around the loop we go again
JOptionPane.showMessageDialog (null,"Guess again");
}
}
}
}