Hi everyone,
This is my code so far. I was just wondering would anyone know how to 'end the run' after 10 correct answers are input by the user ? I was thinking maybe a For loop but I'm not too sure..
import java.util.Scanner;
import java.util.Random;
public class Doorknob
{
public static void main (String args[])
{
int x=0, answer=0;
int number;
Random generator=new Random();
Scanner input=new Scanner (System.in);
do{
int randomInt = generator.nextInt(12);
int randomInt2 = generator.nextInt(12);
System.out.println("");
System.out.println("What is " + randomInt + " * " + randomInt2 + "?");
int result = input.nextInt();
answer = (randomInt*randomInt2);
if (result == answer)
{
System.out.println("Well done");
}
else
while (result != answer)
{
System.out.println("Unfortunately, that's not correct. Please try again.");
System.out.println("");
System.out.println("What is " + randomInt + " * " + randomInt2 + "?");
result = input.nextInt();
if (result == answer)
{
System.out.println("Well done");
}
}
x++;
}
while(x <= 5);
}
}
Any help would be good,
Thanks.