Assignment 66, Hi-Lo with Limited Tries
Code
///Name: Stella Koliavas
///Period: 5
///Program Name: Guess6
///File Name: Guess6.java
///Date Finshed: 1/4/16
import java.util.Scanner;
import java.util.Random;
public class Guess6
{
public static void main (String[] args)
{
Scanner siri = new Scanner(System.in);
Random r = new Random();
int x, s;
int tries = 0;
s = 1 + r.nextInt(100);
System.out.println("Let's play a guessing game, I'm thinking of a number between 1-100.");
System.out.print("Your guess: ");
x = siri.nextInt();
while (tries < 7 && s != x) {
if (s > x )
{
System.out.println(" ");
System.out.println("You guessed too low.");
System.out.print("New guess: ");
x = siri.nextInt();
tries++;
}
if (s < x )
{
System.out.println(" ");
System.out.println("You guessed too high.");
System.out.print("New guess: ");
x = siri.nextInt();
tries++;
}
}
if (s == x)
{
System.out.println("You guessed the number right!");
}
if (tries == 7 )
{
System.out.println("You took too many tries you suck! GAME OVER.");
}
}}
Picture of the output