Ask your own question, for FREE!
Computer Science 20 Online
HumzaAli:

can someone tell me whats wrong in this program /****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ public class Main { public static void main(String[] args){ System.out.println("Hey Guys welcome back to my guessing number game."); System.out.println("Pick a number: "); int maxnumber; int RandomNumber; maxnumber = In.getInt(); RandomNumber = (int)(Math.random()*999 + 1); System.out.println("RandomNumber" + RandomNumber + maxnumber);// remove RandomNumber and maxnumber at the end int number; int tries = 0; int guess; boolean win = false; while (win == false){ System.out.println("Guess a number between 1 and "+ maxnumber +": "); guess = In.getInt(); tries++; if (guess == number){ win = true; } else if(guess < number){ System.out.println("the number you guess is smaller than the secret number. Please try again"); } else if(guess > number){ System.out.println("the number you guess is smaller than the secret number. Please try again"); } } System.out.println("Congratulation You win!"); System.out.println("It took you " + tries + " tries."); } }

Sofia123:

your positioning of parenthesis

0mega:

@sofia123 wrote:
your positioning of parenthesis
parenthesis seem fine actually

poopoopeepee:

You're not reading user input correctly.

poopoopeepee:

If you're meaning to use the scanner class you need to import it and call the method under the class

poopoopeepee:

this line -> maxnumber = In.getInt();

0mega:

I have no clue what code you are trying to run this in, but I pasted the code into GDB and it will display your errors at the bottom

1 attachment
0mega:

@0mega wrote:
I have no clue what code you are trying to run this in, but I pasted the code into GDB and it will display your errors at the bottom
what language*

poopoopeepee:

The language is java and you're trying to run c code @0mega

HumzaAli:

my teacher told me that dont use scanner

0mega:

alright then these are your errors

1 attachment
poopoopeepee:

what did your teacher tell you to use?

HumzaAli:

in.getInt();

poopoopeepee:

@0mega wrote:
alright then these are your errors
Omega obviously @humzaali knows what his errors are. He knew to run the code in online gdb and you don't even know what the language is lol

0mega:

sheesh no need to be rude

poopoopeepee:

@0mega wrote:
sheesh no need to be rude
Yeah the point is to let you know not to help people when you can't, since you're just wasting your own time and adding extra posts that confuse things. If you don't know what language you're looking on based on syntax just don't bother. @HumzaAli , your teacher wants you to use System.in probably. There's really two ways I know of doing this, one with streams and one with scanner. I'm 95% sure you want to use scanner with system.in, since streams are a more advanced topic. https://stackoverflow.com/questions/5488072/reading-in-from-system-in-java

HumzaAli:

but my teacher told me not to use it

poopoopeepee:

Did your teacher provide you a method to handle user input? You can't just call a function and expect it to work without importing it. If you know the name of the function and the package it's supposed to come from I can tell you what the correct syntax is.

poopoopeepee:

There's one more option. Maybe your teacher wants you to use Console.readline() and parse the string as an int? See something like https://www.tutorialspoint.com/java/io/console_readline.htm . You should clarify if you can with your teacher. There aren't that many ways to read user input in java, (or any command line program to be honest. They all use standard system i/o streams after all.)

Blowieee:

I believe you have to make a scanner

HumzaAli:

but my teacher told me not to use scanner don't know why

LemonAide7:

How else would you get user input without a scanner?

LemonAide7:

Also in isn't declared..

LemonAide7:

In.getint?

poopoopeepee:

I gave the asker 2 other ways to get user input without scanner.

LemonAide7:

Seems like you're trying to use a scanner.

LemonAide7:

Seems like you either have to declare variables or use a scanner.

LemonAide7:

Not sure how you could get input without a scanner... to scan the line of the input

LemonAide7:

Pretty sure declaring a scanner would be "Scanner scan = new Scanner();

LemonAide7:

Then you'd use scan.nextInt();

LemonAide7:

I believe.

LemonAide7:

Haven't coding in awhile forgot the syntax.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!