JAVA
ok this game guesses YOUR secret number
but i need to add something that helps it realize that the user of the program is cheating. how would i do that?
like if my number is 43 and it guesses 43 but i chagne it then and the program should be able to detect that the user has changed his/her number (it should no its not wrong). HELP?
eclipe platform used
Code:
import java.io.*;
public class game {
public static void main(String args[])
throws IOException, NumberFormatException {
BufferedReader IN = new BufferedReader(new InputStreamReader(System.in));
int upper, lo, hi, guess, count;
String input;
System.out.println("____________________");
System.out.println("\\ \\");
System.out.println(" \\ Guessing Game \\");
System.out.println(" \\___________________\\");
do {
System.out.print("\nWould you like to view the instructions, (y)es or (n)o? ");
input = IN.readLine();
if (input.equals("y") || input.equals("Y")) {
System.out.println("\n\tYou will set an upper bound and think of a number between");
System.out.println("\t1 and that number. I will try to guess your number in as");
System.out.println("\tfew guesses as possible.");
}
} while ( ! (input.equals("y") || input.equals("Y") || input.equals("n") || input.equals("N")) );
System.out.print("\nEnter the upper bound: ");
upper = Integer.parseInt(IN.readLine());
System.out.println();
count = 0;
lo = 1;
hi = upper;
guess = upper / 2;
do {
System.out.print("\tMy guess is " + guess + ". Is that (l)ow, (h)igh, or (c)orrect? ");
input = IN.readLine();
if (input.equals("l") || input.equals("L")) {
count++;
lo = guess;
guess = (hi + lo) / 2;
} else {
if (input.equals("h") || input.equals("H")) {
count++;
hi = guess;
guess = (hi + lo) / 2;
} else {
if (input.equals("c") || input.equals("C")) {
count++;
System.out.println("\n\tI guessed your number in only " + count + " tries!");
System.out.println("\nThank you for playing Guessing Game.");
break;
}
}
}
} while ( ! (input.equals("c") || input.equals("C")) );
}
}
ok this game guesses YOUR secret number
but i need to add something that helps it realize that the user of the program is cheating. how would i do that?
like if my number is 43 and it guesses 43 but i chagne it then and the program should be able to detect that the user has changed his/her number (it should no its not wrong). HELP?
eclipe platform used