Qbasicnews.com
April 08, 2020, 07:25:07 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Random number guessing game.....  (Read 6821 times)
tannervp
Member
*
Posts: 81



« on: December 01, 2005, 09:26:54 PM »

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: ~~
Logged

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.
tannervp
Member
*
Posts: 81



« Reply #1 on: December 01, 2005, 09:35:54 PM »

please?
Logged

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.
Kevin_theprogrammer
Ancient Guru
****
Posts: 646


Mister Chaucer


WWW
« Reply #2 on: December 01, 2005, 09:53:29 PM »

This belongs in the Newb forum...
Logged


^ 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
WaffleMan
Member
*
Posts: 40



« Reply #3 on: December 01, 2005, 10:01:51 PM »

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!"
Logged

url=http://www.freewebs.com/boxtopstuff/]Planet Boxtop[/url] (Look out for the redesign!)
The only member of QBNF with severe "tomorrow syndrome."
tannervp
Member
*
Posts: 81



« Reply #4 on: December 01, 2005, 10:06:37 PM »

Quote from: "WaffleMan"
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
Logged

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.
Kevin_theprogrammer
Ancient Guru
****
Posts: 646


Mister Chaucer


WWW
« Reply #5 on: December 01, 2005, 10:08:36 PM »

-_-

the command RND

I suggest you read ALL of Vic's tutorials, which can be found on this site...
Logged


^ 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
WaffleMan
Member
*
Posts: 40



« Reply #6 on: December 01, 2005, 10:09:42 PM »

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.
Logged

url=http://www.freewebs.com/boxtopstuff/]Planet Boxtop[/url] (Look out for the redesign!)
The only member of QBNF with severe "tomorrow syndrome."
tannervp
Member
*
Posts: 81



« Reply #7 on: December 01, 2005, 10:10:09 PM »

well, that doesn't help. I need to know how to have it randomize the certain range.
Logged

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.
WaffleMan
Member
*
Posts: 40



« Reply #8 on: December 01, 2005, 10:11:08 PM »

You said you wanted to generate a random number between 1 and 20. The command "INT(RND * 20) + 1" will do that for yo.
Logged

url=http://www.freewebs.com/boxtopstuff/]Planet Boxtop[/url] (Look out for the redesign!)
The only member of QBNF with severe "tomorrow syndrome."
Moneo
Na_th_an
*****
Posts: 1971


« Reply #9 on: December 01, 2005, 10:13:19 PM »

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!
*****
Logged
tannervp
Member
*
Posts: 81



« Reply #10 on: December 01, 2005, 10:19:19 PM »

Quote from: "tannervp"
well, that doesn't help...


so sorry, your post came before mine
Logged

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.
Moneo
Na_th_an
*****
Posts: 1971


« Reply #11 on: December 01, 2005, 10:25:25 PM »

Quote from: "tannervp"
Quote from: "tannervp"
well, that doesn't help...


so sorry, your post came before mine

I'm assuming you meant my (Moneo) post.

Did you read my other suggestions?
*****
Logged
tannervp
Member
*
Posts: 81



« Reply #12 on: December 01, 2005, 10:28:18 PM »

yep. One thing...
Code:
RANDOMIZE TIMER
INPUT "Pick a number:"; num$
getnum% = INT(RND * 20) + 1
IF num$ =


THAT's where I need help.
Logged

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.
Deleter
Na_th_an
*****
Posts: 1293



WWW
« Reply #13 on: December 01, 2005, 10:30:55 PM »

well you can either change num$ to simply num if your user is only going to be inputting numbers. Otherwise you can do the VAL command. VAL(num$) converts your string to a number. then you can do it like this
Code:

IF VAL(num$) = getnum% THEN
    PRINT "YOU WIN"
ELSEIF num > getnum'.....etc

I'd finish the code, but it looks like you need the practice and it would do you no good if I wrote the program for you
Logged

yetifoot
Ancient Guru
****
Posts: 575



« Reply #14 on: December 02, 2005, 12:25:34 AM »

surely if you give someone 5 guesss from 1-20
they can always win by splitting in half till they get it.


10 lower
5   higher
7   higher
8   higher
9   bingo
Logged

EVEN MEN OF STEEL RUST.
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!