Computer Science Canada lottery time! |
Author: | Jenkinz [ Wed May 31, 2006 7:58 am ] | ||
Post subject: | lottery time! | ||
heres a fairly simple program used that allows the user to play the lottery, your bet is how much money *up to 100$* that your are willing to bet, the number your pick is randomly generated, if you pick the correct number *from 1-10* then you win the amount of money you bet *5, comments are appreciated
|
Author: | TheOneTrueGod [ Wed May 31, 2006 1:23 pm ] |
Post subject: | |
Not too bad, but there is plenty of room for improvement. My first big concern is code optimization. Look at the two if statements. Some major redundant code there. Why not just put the "output" part of it after the two statements? Second, some problems with the whole guessing thing. You only randomize the number once, so the "random" number is going to be the same every time you play the game... Also, you don't tell the person that their number has to be between 1 and 10, and you don't regulate it between those values either. You should probably keep track of the user's current amount of money, because as anyone who has gambled knows, you can't just reach down your pants and get more money... You have to have that money to begin with. Also, you didn't account for answers like "n" or "No" or "nO" or something like "I would rather play polo". Also, I can crash it with ease by entering a string when it asks for my bet or my guess. When making a program based around input you need to validate that input. For doing things like this, make sure you have a loop around your checking area, and use the commands intstrok and intstr. Good luck ![]() |
Author: | upthescale [ Wed May 31, 2006 2:04 pm ] |
Post subject: | |
neat, but shudn't it be in sourcecode? |
Author: | Jenkinz [ Wed May 31, 2006 4:18 pm ] |
Post subject: | |
upthescale wrote: neat, but shudn't it be in sourcecode?
sorryt worng section am farily new to the forums and turing |
Author: | ohgeez_ [ Wed May 31, 2006 9:31 pm ] | ||||||
Post subject: | |||||||
neat program. now as theonetruegod said, ur code can be shortened by displaying ur summary after the if statement, ur random number needs to be different time everytime. other things u do to shorten code. - u can initialize ur variables with values by
which i think makes it easier to read since ur not going to change it back to zero later on in your program. - u can also group ur variables together with a comma instead of all those lines
- same goes for the initialization
otherwise. pretty good program =D good luck |
Author: | [Gandalf] [ Wed May 31, 2006 10:21 pm ] |
Post subject: | |
Note: There is a difference between optimization and making your code shorter. Just because one program has less lines than another does not neccessarily mean that it runs faster and more efficiently than longer code. |
Author: | Jenkinz [ Fri Jun 02, 2006 8:40 am ] |
Post subject: | |
yea i just learend to do it that way so i stuck with it |