Assignment #66 Hi-Lo with Limited Tries
Code
///Name: Ian Grant
///Period:5
///Project Name: Hi-Lo with Limited Tries
///File Name:HiLoLimited.java
///12/2/15
import java.util.Random;
import java.util.Scanner;
public class HiLoLimited
{
public static void main(String[] ars)
{
Random r = new Random();
Scanner stuff = new Scanner(System.in);
int gus;
int ans = 1 + r.nextInt(100);
int tries=0;
System.out.println("I'm thinknig of a number between 1-100. You have 7 gueses.");
System.out.print("First Guess: )");
gus= stuff.nextInt();
tries++;
while (tries< 7)
{
if (gus==ans)
System.out.println("Did you cheat? Go buy a lotto ticket.");
while (gus!=ans)
{
if (gus>=ans)
{
System.out.println("Sorry your too high.");
System.out.print("Guess #"+tries+": ");
gus= stuff.nextInt();
tries++;
if (gus==ans)
System.out.println("Good job.");
}
if (gus<=ans)
{
System.out.println("Sorry your too low.");
System.out.print("Guess #"+tries+": ");
gus= stuff.nextInt();
tries++;
if (gus==ans)
System.out.println("Good job.");
}
}
if(tries>=7 && gus!=ans)
System.out.println("You fail at life.");
}
}
}
Output