Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help Needed With Number Guess :D
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Dylan-182




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
illu45




PostPosted: Fri May 20, 2005 10:26 pm   Post subject: (No 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
Dylan-182




PostPosted: Fri May 20, 2005 10:35 pm   Post subject: (No 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
zylum




PostPosted: Fri May 20, 2005 10:52 pm   Post subject: (No subject)

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




PostPosted: Fri May 20, 2005 10:59 pm   Post subject: (No subject)

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




PostPosted: Fri May 20, 2005 11:02 pm   Post subject: (No 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
Dylan-182




PostPosted: Fri May 20, 2005 11:12 pm   Post subject: (No 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
MysticVegeta




PostPosted: Sat May 21, 2005 10:36 am   Post subject: (No subject)

mind posting the code so we can check?
Sponsor
Sponsor
Sponsor
sponsor
illu45




PostPosted: Sat May 21, 2005 1:35 pm   Post subject: (No 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
Neo




PostPosted: Sat May 21, 2005 1:39 pm   Post subject: (No 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)
illu45




PostPosted: Sat May 21, 2005 1:40 pm   Post subject: (No 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...
Dylan-182




PostPosted: Sat May 21, 2005 4:07 pm   Post subject: (No 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
Notoroge




PostPosted: Sat May 21, 2005 4:31 pm   Post subject: (No 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
Cervantes




PostPosted: Sat May 21, 2005 4:46 pm   Post subject: (No 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
MysticVegeta




PostPosted: Sat May 21, 2005 5:15 pm   Post subject: (No subject)

Conclusion: Holtsoft has no intellect whatsoever
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: