help!! need function to ask user if they want and to produce another 10 qs once programs finished
Scanner keyboard = new Scanner(System.in); //given an object scanner and calling it keyboard
int randomOne=0, randomTwo=0, problems=1; //memory allocation holds first random number second random number and problems which acts as a counter to keep track of the amount of problems
int realAnswer=0, userAnswer=0, correct=0, inCorrect=0;//memory allocation product hols the right answer user answer holds the user answer correct holds number of correct and incorrect answers
int choice;
while (problems <= 10){//produces 10 multiplication problems after 10 user will be asked if they wish to have another 10 or to quit
System.out.println("Problem"+ problems + ":"); //prints numbers 1-10
randomOne = generator.nextInt(13);// generates numbers from 1-13
randomTwo = generator.nextInt(13);//generates numbers from 1-13
realAnswer = randomOne * randomTwo; //calculates what these two numbers are equal to
System.out.println(randomOne+ "*" + randomTwo);//asks the user for their guess as to the answer
userAnswer = keyboard.nextInt();
if(userAnswer == realAnswer){
System.out.println("correct! well done! ");
correct++;//increments the variable correct
}
else{
System.out.println("incorrect.Try again" + randomOne + "*" +randomTwo);
while(userAnswer != realAnswer)//this while loop makes the user re-answer the question if they get it wrong
{
inCorrect++;//increments the variable inCorrect
System.out.println(randomOne+"*"+randomTwo);
userAnswer = keyboard.nextInt();
}
}
problems++;//increments the variable Problems
}
System.out.println("you got" + correct + "correct!");
System.out.println("you got" + inCorrect + "incorrect");
// here want to ask if they wish to continue or to exit and if continues selected they get another 10 qs dont know how
}
}
Re: help!! need function to ask user if they want and to produce another 10 qs once programs finished
Consider
1) adding [code] [/code] tags around the posted code in your question above so that it is readable and thus understandable, and
2) adding some text describing just where you're stuck, what you've tried, how it didn't work, etc...