Qbasicnews.com
July 03, 2020, 09:16:32 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 6981 times)
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #15 on: December 02, 2005, 03:16:20 AM »

yes, that's right.
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Moneo
Na_th_an
*****
Posts: 1971


« Reply #16 on: December 02, 2005, 03:16:28 PM »

The "splitting in half" technique is called a Binary Search. Some programmers may think of it, but most regular users wont.
*****
Logged
axipher
Ancient Guru
****
Posts: 544



« Reply #17 on: December 03, 2005, 01:03:39 AM »

binary, a wonderful thing, but anyway there are many tutorials on this, plus theres a program called Learn To Program Basic, from scholastic, i bought it in a bok order in grade 8 like 3 years ago and it had programs premade, one of them was a guessing game too, altough the basic files were different, the coding was BASICally the same, lol, no pun intended but it happened, anyway, the coding aint really that hard no offence, its all basic math really
Logged
yetifoot
Ancient Guru
****
Posts: 575



« Reply #18 on: December 03, 2005, 02:28:39 PM »

Quote
Some programmers may think of it, but most regular users wont.


i wouldnt count on it, we were taught that in the first year of secondary school(age 11-12)
Logged

EVEN MEN OF STEEL RUST.
TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #19 on: December 03, 2005, 04:05:18 PM »

Isn't their a EXAMPLE that shows you how to do this on QbasicNews.Com

Also A Trick i use to make random numbers easier is

Code:
Declare FUNCTION int.rnd(base1 as long, base2 as long) as long

FUNCTION int.rnd(base1 as long, base2 as long) as long
    Return int((rnd*base2)+base1)
END FUNCTION


Int.Rnd ((The lowest possible number),(the highest Possible number)
Logged

url=http://www.sloganizer.net/en/][/url]
axipher
Ancient Guru
****
Posts: 544



« Reply #20 on: December 03, 2005, 07:49:42 PM »

thats nice, i wish the RND function could be used like this

Code:
num = RND(x1 to x2), Step x


i remember one program that u could use to program basuc that worked like this, it was nice, u could go like

Code:
num = RND(0 to 10), Step 2


and it would be a 0,2,4,6,8, or 10, iot worked great

now while were talking about math functions, is there anyway to round a number to no decimal places in qb?
Logged
thegrogen
Ancient QBer
****
Posts: 444



« Reply #21 on: December 03, 2005, 09:08:40 PM »

Quote from: "axipher"

now while were talking about math functions, is there anyway to round a number to no decimal places in qb?


INT()
Logged

.14159265358979323846264338327950288419716939937510582709445
Glarplesnarkleflibbertygibbertygarbethparkentalelelangathaffendoinkadonkeydingdonkaspamahedron.
yetifoot
Ancient Guru
****
Posts: 575



« Reply #22 on: December 03, 2005, 10:49:47 PM »

Code:
Declare FUNCTION int.rnd(base1 as long, base2 as long) as long

FUNCTION int.rnd(base1 as long, base2 as long) as long
    Return int((rnd*base2)+base1)
END FUNCTION


looking at this code posted i tested and it appears incorrect ie

int.rnd(0, 5) should return number in range 0, 1 , 2 ,3, 4, 5

but it will never return 5

This is waht i use requires #include "crt.bi"

Code:
Function GetRand(nmin As uInteger, nmax As uInteger)As uInteger
  GetRand = Int((nmax - nmin + 1) * (rand() / RAND_MAX) + nmin)
End Function


however you can use this also, this is the native fb version, not sure which is faster

Code:
Function GetRand2(nmin As uInteger, nmax As uInteger) As uInteger
  GetRand2 = Int((nmax - nmin + 1) * Rnd + nmin)
End Function



EDIT : sorry just saw im in a QB forum , here is QB one

Code:
Function GetRand2(nmin As Long, nmax As Long) As Long
  GetRand2 = Int((nmax - nmin + 1) * Rnd + nmin)
End Function
Logged

EVEN MEN OF STEEL RUST.
axipher
Ancient Guru
****
Posts: 544



« Reply #23 on: December 04, 2005, 05:20:08 PM »

Quote from: "thegrogen"
Quote from: "axipher"

now while were talking about math functions, is there anyway to round a number to no decimal places in qb?


INT()


i was playing around with a code i dled and figured out that i can use

Code:
PRINT USING "###"; number


it works fine for numbers from -999 to 999 which is wat i want, its for stats and exp in an rpg
Logged
jakeman922
Member
*
Posts: 74



« Reply #24 on: February 08, 2006, 03:06:33 PM »

Quote from: "Kevin_theprogrammer"
I suggest you read ALL of Vic's tutorials, which can be found on this site...


Whatever happened to Vic, anyway? I read his tutorials about 2 years ago. He taught me almost everything I know about programming in any form of BASIC.
Logged

quote="Bruce Raeman"]Anatomy (n): something everyone has, but which looks better on a girl[/quote]
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #25 on: February 08, 2006, 07:17:40 PM »

Isn't  vic "v1ctor"? That would be the guy who made and is still updating FB...
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #26 on: February 08, 2006, 09:17:37 PM »

I really don't think so, Aga. Although we should really ask him. Vic Luce, AKA radiohands made tutorials that taught me loads. Although he disappeared by the time I got involved in the community.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
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!