what is wrong

Started by
15 comments, last by eXtremeMachine 18 years, 10 months ago
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
Advertisement
Quote:Original post by eXtremeMachine
goto 1

I suggest the following: forget everything you know about "programming" and learn a proper language.
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
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.
Free speech for the living, dead men tell no tales,Your laughing finger will never point again...Omerta!Sing for me now!
Quote:Original post by SirLuthor
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.

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!
Ra
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.
thanks thats the stupidest mistake i could have done.


Any way, i read that goto is bad. Why adn how would you have done that
Quote:Original post by Ra
There 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.

Disclaimer: "I am in no way qualified to present advice on any topic concerning anything and can not be held responsible for any damages that my advice may incurr (due to neither my negligence nor yours)"
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.

Link to the FUNCTION command
Link to the SUB command

Good luck!
thanks, i read those but i do not quite understand. could anyone please explain.

This topic is closed to new replies.

Advertisement