Need this question done to the fullelest must be with the challenge by correctin
ID: 3550515 • Letter: N
Question
Need this question done to the fullelest must be with the challenge by correcting my code for this problem. I dont know what's wrong...The solution is on chegg, but people ajust mine instead so it works, With the challange which chegg did not provide.
This program has you, the user, choose a number
between 1 and 10. Then I, the computer, will try
my best to guess it.
Is it 8? (y/n) n
Is it 7? (y/n) n
Is it 5? (y/n) n
Is it 1? (y/n) n
Is it 8? (y/n) n
Is it 1? (y/n) n
Is it 9? (y/n) y
I got your number of 9 correct in 7 guesses.
For an added challenge, consider having the user hint to the computer whether the correct number is higher or lower
than the computer
Explanation / Answer
Try this :
You are facing simple issue .. ..
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.*;
class usernumbersFAIL
{
public static void main(String[] args)
{
Scanner user = new Scanner(System.in);
Random random = new Random();
System.out.println("This program will try to guess a number you pick between 1-30" +
"if the computers guess of your number is wwrong, the computer will prompt you for a hint");
System.out.println("Pick a number bettween 1-30");
final int NUM = user.nextInt();
int result = 0;
max=30;
min=0;
result = Math.floor(Math.random() * (max - min + 1)) + min
while(result != NUM)
{
System.out.println("Is it " + result + "? " + "Enter yes or no:");
String yesno = user.nextLine();
if(yesno == "no")
{
System.out.println("Was the guess higher or lower than your number? Enter high or low");
String highlow = user.nextLine();
if(highlow == "high")
{
result = Math.floor(Math.random() * (max - result + 1)) + min
}
if(highlow == "low")
{
result = Math.floor(Math.random() * (result + min + 1)) + min
}
}
else if ( highlow == "yes")
{
System.out.println("That is correct");
System.exit(0);
}
}
}
}
}
Regards
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.