So I’ve made this guessing game where you the computer randomly picks a number between 1-100 and the user have to guess the correct number. I’ve made that working, now I want to calculate how many times the loop has repeated itself if you may say, or well how many times the user has “guessed”.
This is the current code:
int random = 0;
int a;
random = ((int)(Math.random()*100+1));
System.out.println("Guess the number");
do
{
a = Keyboard.readInt();
if (a > random)
{
System.out.println("Less");
}
if (a == random)
{
System.out.println("Correct");
}
if (a < random)
{
System.out.println("More");
}
}
while (a != random);
1 Answer