Assignemnt #66 and Hi Lo Limited
Code
///Name: Dakota Donahue
///Period: 5
///Project Name: Hi Lo Limited
///File Name: HiLoLimited.java
///Date: 1/12/2016
import java.util.Random;
import java.util.Scanner;
public class HiLoLimited
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int tries = 0;
int mT = 7;
int rN = 1 + r.nextInt(100);
System.out.println("I'm thinking of a number between 1-100. You have 7 guesses.");
System.out.print("First guess: ");
int entry = keyboard.nextInt();
tries++;
while ( entry != rN && tries < mT && entry < rN )
{
System.out.println("Sorry, you are too low.");
System.out.print("Guess # "+ tries + " ");
entry = keyboard.nextInt();
tries++;
}
while ( entry != rN && tries < mT && entry > rN )
{
System.out.println("Sorry, that guess it too high.");
System.out.print("Guess # "+ tries + " ");
entry = keyboard.nextInt();
tries++;
}
if ( entry == rN )
System.out.println("You guessed it! What are the odds?");
else if ( tries >= mT )
System.out.println("Sorry, you didn't guess it in 7 tries. You lose.");
}
}