Computer Science Canada

Help Needed With Number Guess :D

Author:  Dylan-182 [ Fri May 20, 2005 10:22 pm ]
Post subject:  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 Very Happy

Author:  illu45 [ Fri May 20, 2005 10:26 pm ]
Post subject: 

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

Author:  Dylan-182 [ Fri May 20, 2005 10:35 pm ]
Post subject: 

lol yea thats xactly what i was looking for actually but i cant remember how 2 use randint Thinking lol but oh well i guess ill figure it out eventually tnx for the help Very Happy

Author:  zylum [ Fri May 20, 2005 10:52 pm ]
Post subject: 

randomNumber := Rand.Int(1, 10) %genereates a number between 1 and 10 inclusive

Author:  Dylan-182 [ Fri May 20, 2005 10:59 pm ]
Post subject: 

Surprised ty Very Happy lol ohh yeaaa thats how u do it hehe Laughing

Author:  Dylan-182 [ Fri May 20, 2005 11:02 pm ]
Post subject: 

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

Author:  Dylan-182 [ Fri May 20, 2005 11:12 pm ]
Post subject: 

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 Confused

Author:  MysticVegeta [ Sat May 21, 2005 10:36 am ]
Post subject: 

mind posting the code so we can check?

Author:  illu45 [ Sat May 21, 2005 1:35 pm ]
Post subject: 

I would suggest using randint instead of Rand.Int

randint gives a variable a random number within the range, used like this:

code:

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

Author:  Neo [ Sat May 21, 2005 1:39 pm ]
Post subject: 

illu45 wrote:
I would suggest using randint instead of Rand.Int

randint gives a variable a random number within the range, used like this:

code:

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..
code:

var number := Rand.Int (1, 10)

Author:  illu45 [ Sat May 21, 2005 1:40 pm ]
Post subject: 

Neo wrote:
illu45 wrote:
I would suggest using randint instead of Rand.Int

randint gives a variable a random number within the range, used like this:

code:

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..
code:

var number := Rand.Int (1, 10)


You can do that too, I just prefer the randint command...

Author:  Dylan-182 [ Sat May 21, 2005 4:07 pm ]
Post subject: 

lol yea i posted the game on the submitted prgs page Very Happy u shuld cehck it out and give me some feedback on it lol

Author:  Notoroge [ Sat May 21, 2005 4:31 pm ]
Post subject: 

Does your program look anything like this:
Turing:
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
Razz

Author:  Cervantes [ Sat May 21, 2005 4:46 pm ]
Post subject: 

illu45 wrote:
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

Author:  MysticVegeta [ Sat May 21, 2005 5:15 pm ]
Post subject: 

Conclusion: Holtsoft has no intellect whatsoever

Author:  Lazarus [ Sat May 21, 2005 9:00 pm ]
Post subject: 

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.


: