-
February 16th, 2017, 12:50 PM
#1
Need help fast with java programming
I was sick for a month and now im super busy studying and all. I have a program to code and i have no idea how to do it and im kinda desperate... desperate as hell. I need this program to be done for the end of this weekend:
The program has to generate a random number between -1000 and 1000. User has 11 guesses max. Then the person guesses, if the quess is too high then the program has to say „your guess was too high“ and if the guess was too low then „your guess was too low“. If the user guesses the number then the program has to say „you found the hidden number“. If the user didnt find the number after 11 guesses then: „you lost. The hidden number is -(hidden number)-.
Normally i would not ask for a solution, but desperate times call for desperate measures. If anyone can help me, it would be AMAZING.
-
February 16th, 2017, 04:04 PM
#2
Re: Need help fast with java programming
We've not supposed to provide code for homework assignments - however in the circumstances... Sorry I can't help with Java code as I only program in c/c++, but if some c++ code for this is any help.
In general, you generate the number to be found. Then you have a loop that checks if the number of guesses exceeds the max allowed and if it has then the loop is terminated. In the loop ask for the guess. If less then, display too low, if greater than display too high. In both these cases increment the number of guesses count. If the guess equals the number then display you found and break out of the loop. After the loop, compare the number of guesses to the max allowed. If equal then display you lost.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 17th, 2017, 10:27 AM
#3
Re: Need help fast with java programming
generate a random number between -1000 and 1000.
See the Random class. It has methods for generating random numbers.
Since the range of desired random numbers is 2000, ask the Random class's method for a number in that range and then subtract 1000 from what it returns to map the returned number into the desired range.
Norm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|