//Guessing Game
//Alex Perez
//01/21/04  PROJECT6N1

import TerminalIO.*;
import java.util.Random;


public class Project6n1 {
	public static void main (String [] args) {
		Random rand = new Random();

		KeyboardReader reader = new KeyboardReader();
		
		int nGuesses = 0,
			guess;
		String choose;
		
		int number = rand.nextInt(100);	
		while(1 == 1){
			
			System.out.println("Guess a number from 1 to 100: ");
			guess = reader.readInt("What is your guess? "); 
			
			//tests if guess is too high, low, or equal to number
			if(guess > number){
				System.out.println("Too High!");
				nGuesses++;
			} else if(guess < number){
				System.out.println("Too Low!");
				nGuesses++;				
			} else if(guess == number){
				System.out.println("You Win!");
				System.out.println("You had " + nGuesses + " try/tries");
				choose = reader.readLine("Again? (Y/N): ");
				
				//check if the player eants to go again			
				if(choose == "N" || choose == "n"){
					//exit the program
					System.exit(0);
				}
				//new number for new game
				number = rand.nextInt(100);
			}	
		}
		
	}
}
