• 12
• 14
• 13
• 10
• 11

what is wrong

This topic is 4714 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

let a=0 let x=0 Print "game" Print "Press any key to continue" WHILE INKEY$= "" X=RND() * 100 wend cls 1: input "What is the number"; a If x = a then print "yes, your number is"; a end if if x < a then print "Too high, your number is"; a goto 1 end if if x > a then print "Too high, your number is"; a goto 1 end if sleep theres the code, it is done in freebasic when i run it, it allways says "Too high, your number is and gives the number you put in" WHILE INKEY$ = "" X=RND() * 100 wend print x; sleep when i run that code it comes displays a different number each time why is the test command not working properly

Share on other sites
Quote:
 Original post by eXtremeMachinegoto 1

I suggest the following: forget everything you know about "programming" and learn a proper language.

Share on other sites
whats is wrong with that i just want to try one language get above go the try another and so on. then decided where to go.

and whats is wrong with goto 1

Share on other sites
Goto makes baby jesus cry, kills your karma faster then anything else I know of, and it considered one of the worst things you can do. Goto littered code is one of the most unreadable things known to man (things intentionally made unreadable not taken into account), right up there with RSA encrypted documents and compressed video data. What you want to use are loops, not goto.

Share on other sites
Quote:
 Original post by SirLuthorGoto makes baby jesus cry, kills your karma faster then anything else I know of, and it considered one of the worst things you can do. Goto littered code is one of the most unreadable things known to man (things intentionally made unreadable not taken into account), right up there with RSA encrypted documents and compressed video data. What you want to use are loops, not goto.

There is nothing wrong with goto, especially in BASIC, and especially in very small apps like this one. Loop constructs in BASIC aren't too spectacular, and the code is perfectly readable as it is.

The real problem is this:
if x < a thenprint "Too high, your number is"; agoto 1end ifif x > a thenprint "Too high, your number is"; agoto 1end if
You have "Too high, your number is" in both if statements!

Share on other sites
Does it work correctly if you guess the number exactly?

One reason it might always be saying "Too high" is that you put the same message for the test cases of x < a and x > a. Try changing the print under x > a to "Too low".

Also, I think it would be easier (at least with the way you phrased your output) for people to read if you tested a = x, a < x, a > x since a is the variable that the user's guess is stored in.

Share on other sites
thanks thats the stupidest mistake i could have done.

Share on other sites
Quote:
 Original post by RaThere is nothing wrong with goto, especially in BASIC, and especially in very small apps like this one.

*nods*

While it's not a concept to base a large program around, they are often the easiest way to do something. And oftentimes in basic the only way to do it with any amount of elegance.

There is nothing wrong with learning BASIC. I wrote space invaders, arkanoid, pac man, and a 3D wireframe renderer in BASIC. The simple syntax gave me the start in programming that I needed. I still believe it to be one of the best learning languages around.

Share on other sites
In response to alternatives to the GOTO statement in FreeBasic, I did some searching for you. I've never used FreeBasic, but I hope this helps.

For larger programs, the use of the SUB and FUNCTION commands may be preferable to using GOTO.

Good luck!