+ 2
Can anyone explain me why this code doesn't work, please ?
This code works on my computer but not on SoloLearn https://code.sololearn.com/cD0Wwbz4Ucx3/?ref=app
5 Antworten
+ 8
sololearn playground can only take inputs at the beginning of runtime
you can have multiple inputs seperated by new line
73
982
636
324
124
93
27
......
but of course for this kind of code is a problem :/
at the moment only JavaScript allows to have different inputs on runtime if you wish to try and convert your code
+ 7
that's not your mistake, sadly sololearn's input isn't the best yet, it can only take input when you run the code so you can put in some numbers at the beginning by pressing 'enter' after each number and it should work
+ 4
The error occurs on sc.nextInt() so to fix this in case the user only entered one input, you can add && sc.hasNext() to your while loop condition.
Also add a condition to your "Congratulations" message to pop only if the user found the secret.
I know that's not exactly how you wanted your program to work but because of SoloLearn's input system, that's the solution I came up with :)
+ 1
Oh damn it... Unfortunately, that's not a good first code to make it public. I will try to make a new one which work with SoloLearn's input system. Anyway, thank you so much guys for bringing your quick help to a beginner like me :).
0
Another thing:
If you enter the right number, you will get the message that is too high + the congratulation message that you found it.
To fix it, you should check if your number is higher than the secret too, but not whatever - else (because here 'else' will accepts higher or equal numbers).