
-----------------------------------
Dylan-182
Fri May 20, 2005 10:22 pm

Help Needed With Number Guess :D
-----------------------------------
as the title says i need some help with a number guess prg. im just kinda fiddling with it in my spare time and i know that i have to use if statments and variables and such but also i want a random number generator. So basically i know WHAT i need i just dont know the proper structure so if ne1 could help it would b much appreciated :D

-----------------------------------
illu45
Fri May 20, 2005 10:26 pm


-----------------------------------
Well, I'm not sure what you mean by proper structure, but here's my idea:

1) Start off with a brief introduction of what you're doing

2) You may want to get the user to declare the range of the number (1-10, 2-5, 100-250, etc.)

3) Generate a random integer within the range using the randint command

4) Get guesses in a loop, exiting when guess = number 

5) If you want, use if statements to tell the person to guess higher or lower

6) Also, you can add in a counter to keep track of the number of guesses. 

Thats pretty much it,
illu45

-----------------------------------
Dylan-182
Fri May 20, 2005 10:35 pm


-----------------------------------
lol yea thats xactly what i was looking for actually but i cant remember how 2 use randint :think: lol but oh well i guess ill figure it out eventually tnx for the help :D

-----------------------------------
zylum
Fri May 20, 2005 10:52 pm


-----------------------------------
randomNumber := Rand.Int(1, 10) %genereates a number between 1 and 10 inclusive

-----------------------------------
Dylan-182
Fri May 20, 2005 10:59 pm


-----------------------------------
:o ty :D lol ohh yeaaa thats how u do it hehe  :lol:

-----------------------------------
Dylan-182
Fri May 20, 2005 11:02 pm


-----------------------------------
oh wait what was the code for a counter again so i can count the number of times they have guessed then exit when it is 10

-----------------------------------
Dylan-182
Fri May 20, 2005 11:12 pm


-----------------------------------
umm ok i have it set up so that if its 2 low itll say 2 low and if its 2 high it says 2 high but it wont exit when then guess = the random number :?

-----------------------------------
MysticVegeta
Sat May 21, 2005 10:36 am


-----------------------------------
mind posting the code so we can check?

-----------------------------------
illu45
Sat May 21, 2005 1:35 pm


-----------------------------------
I would suggest using randint instead of Rand.Int

randint gives a variable a random number within the range, used like this:


var number : int
randint (number,1,10)


That will set number to an integer between 1 and 10, then you can use it as your point of reference for ifs and exit whens

-----------------------------------
Neo
Sat May 21, 2005 1:39 pm


-----------------------------------
I would suggest using randint instead of Rand.Int

randint gives a variable a random number within the range, used like this:


var number : int
randint (number,1,10)


That will set number to an integer between 1 and 10, then you can use it as your point of reference for ifs and exit whens

Umm.. 

var number := Rand.Int (1, 10)


-----------------------------------
illu45
Sat May 21, 2005 1:40 pm


-----------------------------------
I would suggest using randint instead of Rand.Int

randint gives a variable a random number within the range, used like this:


var number : int
randint (number,1,10)


That will set number to an integer between 1 and 10, then you can use it as your point of reference for ifs and exit whens

Umm.. 

var number := Rand.Int (1, 10)


You can do that too, I just prefer the randint command...

-----------------------------------
Dylan-182
Sat May 21, 2005 4:07 pm


-----------------------------------
lol yea i posted the game on the submitted prgs page :D u shuld cehck it out and give me some feedback on it lol

-----------------------------------
Notoroge
Sat May 21, 2005 4:31 pm


-----------------------------------
Does your program look anything like this:
var heh, guess : int := Rand.Int (1, 10)
loop
    put "Guess a number between 1 and 10: " ..
    get guess
    if guess = heh then
        put "you win"
        return
    else
        put "nope, guess again!"
    end if
end loop:P

-----------------------------------
Cervantes
Sat May 21, 2005 4:46 pm


-----------------------------------
You can do that too, I just prefer the randint command...
I don't understand why.  randint forces you to assign the random value to a variable.  If you use Rand.Int, you have the choice of assigning it to a value or doing something else with it.  If you only need it one time, say for a calculation, you don't have to go to the bother of creating a variable just for it.
Functions > Procedures

-----------------------------------
MysticVegeta
Sat May 21, 2005 5:15 pm


-----------------------------------
Conclusion: Holtsoft has no intellect whatsoever

-----------------------------------
Lazarus
Sat May 21, 2005 9:00 pm


-----------------------------------
Did you know the randint command isn't really random. It gets it's supposed "Random" numbers from the computer clock, there is a pattern over a 24 hours period.
