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.

Newcomers DBPro Corner / annoying syntax error please help

Author
Message
luke130697
13
Years of Service
User Offline
Joined: 16th Mar 2011
Location:
Posted: 18th Mar 2011 18:36
Hi, I tried to make a handy conversion program, where you are taken to a menu, from there you choose the conversion tool and then use it. No matter what I do I get a syntax error.
Here is the code:

do
choice:
input "Which gadget do you wish to use: <c>entigrade to farenheight, <ca>lculator or <p>ounds to dollars. To exit type 'e'", $choice
if $choice = c
goto cent
if $choice = ca
goto calc
if $choice = p
goto pound
if $choice = e
print "3"
wait 1000
print "2"
wait 1000
print "1"
wait 1000
print "0"
wait 1000
end
else
print "Not a valid choice"
goto choice
endif

calc:
print "welcome to the calculator, type 'menu' to go to menu. "
do
input calculation#
wait 500
print calculation#
loop
if str$(calculation#) = "menu" then goto choice
endif

pound:
print "welcome to the pounds to dollars translator, type 'menu' to go to menu. "
dollars# = pounds#*1.6504
do
input pounds#
wait 500
print pounds#;" pounds is equal to "; dollars#;"."

LOOP
if str$(pounds#) = "menu" then goto choice
endif


cent:
print "welcome to the centigrade to farenheight translator, type 'menu' to go to the menu. "
farenheight# = centegrade#*1.8+32
do
input centegrade#
print str$(centegrade#);" centegrade is equal to "; farenheight#; " farenheight."
loop
if str$(centegrade#) = "menu"
goto choice
endif

Luke Eric Roy Davison
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 18th Mar 2011 20:04
Mainly your problem was to do with not closing off If statements properly.

This compiles but i dont think it works as intended.



Basically you popped a couple of Endifs when you used an If Then statement which you dont need, secondly you missed a few endif's when you needed them on the back of some if statements. Hope this helps.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Mar 2011 20:06
From looking at your code, it seems that you do not understand the very basics of programming - I'd suggest looking in the tutorial thread and starting with either TDK's tutorials, or with Dan's videos and getting a good grounding there.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Mar 2011 20:12 Edited at: 18th Mar 2011 20:14
Yeah it's what Somarl said. It's because you don't close most of your IF/THEN statements. If you use THEN you don't need an ENDIF to close the IF statement... but if you don't use THEN you must use ENDIF.

Now that you know how to use GOTO stop using it. All it does is make the code hard to follow and will ultimately create spaghetti code (see signature). GOSUB is a better alternative and functions are even better but I'll just show you GOSUB for now. GOSUB is just like GOTO but when it hits a RETURN it'll go back to the line right after the GOSUB.

When detecting for a string put the $ at the end of the variable name (not at the beginning) and when checking strings always make sure to put the word you're detecting in quotes.

When you get input thats an integer or a float (the #) it won't see it as a string to detect words like "menu". The best solution is to get the user input as a string then convert it to a number later with the VAL() command if "menu" hasn't been seen.

The one problem with getting input and detecting a word is the case of the letters matters. If a user typed "Menu", "mENu", or "menU" it won't detect it unless the user types "menu". To prevent user error like this always convert the user input to higher case or lower case with the commands UPPER$() or LOWER$().



And yeah do what IanM said and check out the tutorials.

luke130697
13
Years of Service
User Offline
Joined: 16th Mar 2011
Location:
Posted: 18th Mar 2011 20:46
Thanks for the help

Luke Eric Roy Davison

Login to post a reply

Server time is: 2024-09-29 02:33:59
Your offset time is: 2024-09-29 02:33:59