I already ran my program through the SourceCoder, but I know that the SourceCoder's not perfect. Here it is:

GUESGAME wrote:

::DCS
:FF818181818181FF
:ClrHome
:Input "Maximum?",U
:While U≤1
:Disp "Invalid number.
:Input "Try again.",U
:End
:1→E
:randInt(0,U→R
:Input "Guess my num.",G
:While G≠R
:While G>U or G<0
:Disp "Invalid number.
:Input "Try again.",G
:End
:If G>R
:Then
:Disp "Too high.
:Input "Try again.",G
:E+1→E
:End
:If G<R
:Then
:Disp "Too low.
:Input "Try again.",G
:E+1→E
:End
:End
:Disp "Wow, you got it!
*****:Disp "In",E,"tries!*****
:Repeat getKey
:End
:ClrHome
:Output(1,1,"
:DelVar GDelVar RDelVar UDelVar E


This is a guessing game in which you input the maximum number that the randInt( can generate, and then proceed to guess the number. I'm most concerned about the code in between the stars. Any optimization ideas?
That's pretty much the most optimized, but you can improve the Disp code using the Output command to make it look nicer.
Hello, everyone!

How about this:


Code:
::DCS
:FF818181818181FF
:0→E
:-1→G
:"low._high._____→Str1
:ClrHome
:Input "Maximum?",U
:not(U)+(U=1)+abs(iPart(U→U
:randInt(0,U→R
:While G≠R
:Input "Guess my number.",G
:If .5U≥abs(G-.5U
:Then
:Pause "Too"+sub(Str1,1+4(G>R)+10(G=R),5
:E+1→E
:Else
:Pause "Invalid number.
:End
:End
:Disp "Wow, you got it!","in",E
:Pause "tries!
:ClrHome
:DelVar GDelVar RDelVar UDelVar EOutput(1,1,"


Since my Windows computer's broken, I never got to test it, but here it be. Hope I did it right (1:00 in the morning where I am, half-asleep).

Edit: My post didn't display the spaces in Str1 properly, so I made 'em underscores instead.
Here's some optimizations on that:

Code:
::DCS
:FF818181818181FF
:Delvar E(-)1→G
:"low. high.      →Str1
:ClrHome
:Input "Maximum?",U
:not(U)+(U=1)+abs(iPart(U→U
:randInt(0,U→R
:While G≠R
:Input "Guess my number.",G
:If .5U≥abs(G-.5U
:Then
:Pause "Too "+sub(Str1,1+4(G>R)+10(G=R),5
:E+1→E
:Else
:Pause "Invalid number.
:End
:End
:Disp "Wow, you got it!","in",E
:Pause "tries!
:ClrHome
:DelVar GDelVar RDelVar UDelVar E"
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement