Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random number guessing game.....
#1
I am trying to make a guessing game that starts with a random number between 1 and 20 that gives the player 5 guesses, and after each guess tells them whether they are too high or too low.


I want HELP, not the code

~~ :rotfl: :bounce: Charlie :bounce: :rotfl: ~~
y name is Nobody, and nobody's perfect. So now I am perfect Tongue

98% of the teenage population smokes or has smoked pot. If you're one of the 2% who hasn't, copy and paste this in your signature.
Reply
#2
please?
y name is Nobody, and nobody's perfect. So now I am perfect Tongue

98% of the teenage population smokes or has smoked pot. If you're one of the 2% who hasn't, copy and paste this in your signature.
Reply
#3
This belongs in the Newb forum...
[Image: 1403.png]
^ Infrosoft
http://www.thecodeyouneed.us.to/ - A wiki of source code, mostly in PHP and FreeBASIC
http://www.osadvocacy.uk.to/ - Your opinion matters no matter your OS
Reply
#4
Simple: First, randomly generate a number, then offer the user a guess. Take the user's input and compare it with the generated number: if the user's number is higher than the generated number, print "Too high!" If the user's number is lower, then print "Too low!"

Also, have a tries counter that adds 1 to itself every time the user misses the guess. If the user fails on all 5 tries, then print "Game over!"

But instead of that, have a generic tries counter, so you can let the user know how well he did. Example: "Congradulations! You got the number in *num* tries!"
url=http://www.freewebs.com/boxtopstuff/]Planet Boxtop[/url] (Look out for the redesign!)
The only member of QBNF with severe "tomorrow syndrome."
Reply
#5
Quote:Simple: First, randomly generate a number, then offer the user a guess. Take the user's input and compare it with the generated number: if the user's number is higher than the generated number, print "Too high!" If the user's number is lower, then print "Too low!"

Also, have a tries counter that adds 1 to itself every time the user misses the guess. If the user fails on all 5 tries, then print "Game over!"

But instead of that, have a generic tries counter, so you can let the user know how well he did. Example: "Congradulations! You got the number in num tries!"

I just don't know how to make a random number generator thingy
y name is Nobody, and nobody's perfect. So now I am perfect Tongue

98% of the teenage population smokes or has smoked pot. If you're one of the 2% who hasn't, copy and paste this in your signature.
Reply
#6
-_-

the command RND

I suggest you read ALL of Vic's tutorials, which can be found on this site...
[Image: 1403.png]
^ Infrosoft
http://www.thecodeyouneed.us.to/ - A wiki of source code, mostly in PHP and FreeBASIC
http://www.osadvocacy.uk.to/ - Your opinion matters no matter your OS
Reply
#7
There's a simple command I learned:

getnum% = INT(RND * num) + 1

where "num" represents the maximum value between 1 and said number. Make sure you add "RANDOMIZE TIMER" up at the top so the number is different everytime the program is run.

Kev: Yeah, but RND doesn't generate whole numbers, only decimals smaller than 1.
url=http://www.freewebs.com/boxtopstuff/]Planet Boxtop[/url] (Look out for the redesign!)
The only member of QBNF with severe "tomorrow syndrome."
Reply
#8
well, that doesn't help. I need to know how to have it randomize the certain range.
y name is Nobody, and nobody's perfect. So now I am perfect Tongue

98% of the teenage population smokes or has smoked pot. If you're one of the 2% who hasn't, copy and paste this in your signature.
Reply
#9
You said you wanted to generate a random number between 1 and 20. The command "INT(RND * 20) + 1" will do that for yo.
url=http://www.freewebs.com/boxtopstuff/]Planet Boxtop[/url] (Look out for the redesign!)
The only member of QBNF with severe "tomorrow syndrome."
Reply
#10
Ok, since you don't want code, then I have to assume that you know how to code getting a random number between 1 and 20. Am I correct so far?
If NO, then you need coding help.
If YES, continue.

The rest is pretty trivial, with a few considerations like:

1) You should validate the user's guesses to make sure that they are between 1 and 20. If his guess is invalid, print an error message saying that it must be between 1-20, and don't count his error against the 5 total guesses.

2) Your response cannot be just "too low" or "too high", he might just guess the right number.

3) You could give him a little help, like:
- make an array of 20 entries, corresponding to the 20 numbers.
- when he makes a valid (1-20) guess that is not the answer, test to see if the guess location in the table is greater than zero. If it is, print a message saying that that guess was already used, and don't penalize him. If it is zero, just add one to the array location.

4) More sophisticated help could be given, like if the answer is 9 and he already tried 5 which you told him was too low, Now he says 3, which is obviously too low also. You could figure a way of warning him.

Have fun!
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)