Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / I'm thinking of a number from 1 to 10

Author
Message
Timber Wolf
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location:
Posted: 23rd Oct 2005 05:32 Edited at: 23rd Oct 2005 17:03
I'm teaching myself to use db right now, so I'm starting with simple things such as this. This is a simple full screen program that lets you guess a number from 1 to 10. You are told whether you were right, close, or dead wrong, and repeats until you win. I used mousex and mousey multiplied by eachother and a random number to 1000 as the seed for randomiztion to try and make it less sequencial. hopefully this can help other begginners to the language understand some basics. If anything about this can be done simpler then how I've done it, please post.




I known: HTML, How to 3dmodel
learning: Javascript, C++, Basic
Millenium7
19
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 23rd Oct 2005 11:08 Edited at: 23rd Oct 2005 11:11
Once you learn the language concentrate on optimising your code because its more how you write than what you write that matters. Your using the randomise command to stop it generating the same sequence every time, good. But theres a better way than what your doing, whats a return variable thats never the same or highly unlikely to be the same without the user doing anything? (in this case moving the mouse)

Timer() is the best so try randomise timer()

Another line that can be optimised is...

change to

So it picks up anything less than 1 or more than 10 as being an error, rather than just 0. If you were writing a larger more complex program - depending on how it works - you could optimise it furthur, for example if you had a program execute that same 'if then' statement several times but sometimes needed different numbers, instead of writing the same code 100 times you could do something like...



If you dont know about functions yet ignore that 2nd part, their best used in more complex programs with routines that need to be called several times with differing values
Timber Wolf
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location:
Posted: 23rd Oct 2005 16:33 Edited at: 23rd Oct 2005 17:03
Hey, thanks for the info man. Timer works alot better then my mouse coordinates. I can see the second part really helping if I were to give the user the choice of which number's guessing, and I can see how it could be applied to alot more.

Thanks again

/edit
I took some time to mess around with what you told me, and I know have a program that allows the user to choose the start and ending number. It will also tell the user if they made the end number equal to or less then the start number, and have them put in new numbers




I known: HTML, How to 3dmodel
learning: Javascript, C++, Basic

Login to post a reply

Server time is: 2024-11-23 11:08:46
Your offset time is: 2024-11-23 11:08:46