I’m very new to coding, taking my first coding class in college this quarter. I’m currently writing code for a guessing game in which every time the player guesses the text will display “Try your first guess,” “Try your second guess,” and “Try your third guess.” My issue is figuring out how to make my code display ‘first’ ‘second’ and ‘third.’ I have tried setting an int tied to number of tries that will increase every time the player tries, but I cannot seem to figure it out. Sorry if this question is hard to figure out but here is my code so far.
import java.util.Scanner; class Guess{ public static void main( String[] args ){ Scanner sc = new Scanner(System.in); int correctnumber = (int)Math.round(Math.random()*10); int Guesses = 3; int userguesses = 0; int numberoftries = 0; System.out.println("I am thinking of number between 1 and 10. You have three chances. Godspeed."); while(Guesses > 0){ System.out.print("Enter your first guess: "); userguesses = sc.nextInt(); if(userguesses == correctnumber) { System.out.println("Winner!"); break; } else if(Guesses == 0 && userguesses != correctnumber) { System.out.println("You Lose! The correct answer was " +correctnumber); break; } else if(userguesses > correctnumber) { System.out.println("Your answer is too high. Please try again."); } else if (userguesses < correctnumber) { System.out.println("Your answer is too low. Please try again."); } Guesses--; numberoftries ++; } } }