for this im supposed to create a program that randomly chooses a number between 1-100 for the user to guess and if the user is wrong then ask for another guess
then wen the user gets it right, to then state the amount of tries and to ask if the user wants to play again
heres the code that my friend and I have com up with...
import java.util.Scanner;
import java.util.Random;
import cs1.Keyboard;
public class Guessing
{
public static void main (String[] args)
{
final int max=10;
int answer=0;
int guess=0;
int reportCount=0;
int decsion;
Scanner scan = new Scanner (System.in);
Random generator = new Random();
answer = generator.nextInt(max) + 1;
System.out.println ("I'm thinking of a number between 1 and "+max+".");
System.out.print ("Guess what it is: ");
guess = scan.nextInt();
while(true){
System.out.print ("Sorry wrong answer please guess again: ");
guess = scan.nextInt();
if (guess==answer){
System.out.println("You got it! Good Guessing!");
break; }
else
System.out.print ("");}
for(guess=1;guess<=500;guess++)
reportCount=reportCount+guess;
System.out.println(reportCount);
{
String decision,input;
decision=new String("again");
System.out.println("Type the word:'again' if you want to play another round. ");
input = Keyboard.readString();
while(input.compareTo(decision)!=0)
{
System.out.println("I did not understand you please type again.");
input = Keyboard.readString();
}
}
}
wat i need help on is how to count the amount of tries of the user and how to make the code restart at the top for another game