The program is supposed to ask the user for the range of the guesing game (1-10), ask them how many guesses they want, and then ask them for a guess. Then it prints out Cold if he guess is greater than 25% of the answer, print WARM if its between 10%-25% and print HOT if its within 10%...PLEASE HELP!
/**
*
*/
package edu.ilstu;
import java.util.Scanner;
import java.util.Random;
/**
* @author Scott Swingle
*
*/
public class GuessingGame {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner keyboard = new Scanner (System.in);
Random generator = new Random();
int guesses;
int guessNum = 0;
double difference = 0;
int answer;
double guess = 0;
String another = "y";
boolean flag = false;
boolean anotherFlag = true;
int count = 1;
System.out.print("Please enter a number to indicate the range of the game (10,20,30)");
guessNum = keyboard.nextInt();
System.out.println("How many guesses should I allow?");
guesses = keyboard.nextInt();
System.out.println("Let's Play. I've chosen my number.");
answer = generator.nextInt(guessNum) + 1;
System.out.println("It's a whole number between 1 and " + guessNum + (": "));
flag = false;
guess = keyboard.nextInt();
while(!flag || count <= guesses)
{
answer = generator.nextInt(guessNum) + 1;
System.out.println("It's a whole number between 1 and " + guessNum + (": "));
flag = false;
guess = keyboard.nextInt();
{
if(guess == answer)
{
System.out.println("You guessed correctly! Good Job");
flag = true;
}
else if(difference / guessNum <= .10)
{
System.out.println("Hot! Try Again: ");
count++;
}
else if(difference /guessNum <= .25)
{
System.out.println("Warm! Try Again: ");
count++;
}
else
{
System.out.println("Cold! Try Again ");
count++;
}
if(guess > answer)
{
difference = guess - answer;
}
else if (guess < answer)
{
difference = answer - guess;
guess = keyboard.nextInt();
}
System.out.println();
System.out.println("Would you like to play again? (y/n)");
another = keyboard.next();
if(another.equalsIgnoreCase("y") == true)
{
anotherFlag = true;
}
else
{
anotherFlag = false;
}
}
}
}
}