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.

DarkBASIC Professional Discussion / if else input variable

Author
Message
Graysire
12
Years of Service
User Offline
Joined: 18th Oct 2013
Location:
Posted: 14th Mar 2014 17:54
input "Enter Answer: ";VE1answer
if VE1answer = Bilbo then gosub VE2Section else gosub FailSection

this is supposed to go to the next quiz question, and if you input wrong then you go to the fail section, no matter what I input it goes to VE2Secrion.
ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 14th Mar 2014 18:06 Edited at: 14th Mar 2014 18:29
Is Bilbo supposed to be a variable? Or do you mean the string "Bilbo"? If so, put it in quotation marks.

Also, you should probably write this:

input "Enter Answer: ",VE1answer

instead of this:

input "Enter Answer: ";VE1answer

As VE1answer is meant to be the second parameter, and not part of the question string. (Edit: Apparently this doesn't make a difference)

WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 14th Mar 2014 18:09 Edited at: 14th Mar 2014 18:12
Hope this helps.

Graysire
12
Years of Service
User Offline
Joined: 18th Oct 2013
Location:
Posted: 14th Mar 2014 18:10
Bilbo is what the correct answer is.
Graysire
12
Years of Service
User Offline
Joined: 18th Oct 2013
Location:
Posted: 14th Mar 2014 18:14
says lower$ does not match string
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 14th Mar 2014 18:18
Because you haven’t dimensioned VE1answer as a string variable; see first line of snippet.
Graysire
12
Years of Service
User Offline
Joined: 18th Oct 2013
Location:
Posted: 14th Mar 2014 18:27
IT WORKS!!!! thanks
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 14th Mar 2014 18:34
Great
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 17th Mar 2014 20:45
Just beware of GOSUBing to a new section like that.
Eventually, you'll overflow the stack and the program may crash.

tiffer
20
Years of Service
User Offline
Joined: 6th Apr 2006
Location: Scotland
Posted: 25th Mar 2014 15:24
He ought to replace Gosub with Goto.

Cwatson
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 26th Mar 2014 01:49
Quote: "He ought to replace Gosub with Goto"

No! (Unless that was sarcasm, in which case, No! They'll believe it)


He should replace gosub with decent code.

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 26th Mar 2014 14:17 Edited at: 26th Mar 2014 14:19
Indeed; Gosub is being used where an IF block would be used in good practice. Here is the good way of programming your questions from now on, although this is just a step in the right direction, there is still something wrong which I will leave you to figure out:



Only one CLS command is used outside of the IF branch because only the instructions dependent on the answers go inside the IF branch, or the Else branch.

This is the same for all structured programming instructions; depending on the logic, context and input; what follows is enclosed in a block of code.

Use sub routine GOSUB calls for just that; to run a routine subjected to a major section of code; not as a way of delegating small instructions.

There is a problem with your code and my example that I have not pointed out; do you know what it is? I will give you a hint; 'Try again?'

Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 26th Mar 2014 14:24
Quote: "There is a problem with your code and my example that I have not pointed out; do you know what it is? I will give you a hint; 'Try again?'"

I think that semicolon will cause even greater issues...


"Why do programmers get Halloween and Christmas mixed up?"

Login to post a reply

Server time is: 2026-07-06 10:34:56
Your offset time is: 2026-07-06 10:34:56