DBPro Newcomers / No idea what i've done wrong... |
| Author | Message | ||
|
TillyLala
User Joined: Mon Jul 6th 2009 Location: In the little cupboard under the stairs |
Hey... Only me Right.. I needed to revise for a test on statistics for psychology tomorrow, so i thought i'd practise a bit of coding at the same time. The code compiles and runs, however.. When I run it and it asks the 1st question it just asks me the question again.. but if i comment the whole first part out it seems to let me answer fine? Help please + Code Snippet ![]() |
||
| Back to top |
|||
|
Daniel wright 2311
User ![]() Joined: Sat Dec 22nd 2007 Location: pueblo, colorado |
if your asking why its going to the first question asked over and over its becouse you asked it to. endif GoTo Start if this is not what your asking then i dont know? I tested it, it ran fine ok i see it now do this If hypothesis$ = "Correlation" Print "Use Spearmans Rho" endif if wait key()=1 CLS GoTo Start endif DSW |
||
| Back to top |
|||
|
Satchmo
User Joined: Sun May 29th 2005 Location: Cyberspace |
It seems you have two goto starts, outside of the IF statements. That will create an infinite loop I.E Start: Goto Start It will keep working over and over again like that, I'm not sure what the answer to "What was the hypothesis?" question, but it seem that You need to check for the correct answer as well. Here is the fixed code, just replace with the correct answer. + Code Snippet Please note I've only fixed the first question, and BTW you will need to use a different label for each question(I.E. NextQuestion2,NextQuestion3) ![]() |
||
| Back to top |
|||
|
TillyLala
User Joined: Mon Jul 6th 2009 Location: In the little cupboard under the stairs |
Thank you for the help! Satchmo - Thanks, i couldn't work out how to put more than one start and was getting really rather mad with it ![]() |
||
| Back to top |
|||
|
Google Ad
AdBot Joined: Aug 26th 2002 Location: Everywhere |
|||
| Back to top |
|||
|
Rich Dersheimer
User ![]() Joined: Wed Jul 1st 2009 Location: Driving a Mark 4 Mod 5 Badger Hovertank! |
Your GoTo Start commands are all outside the "if" tests. Follow your logic... Start: Input a string Check the string, print something clear the screen, wait for a key GoTo Start and do the same question, over and over and over You never get past the GoTo after the first "if" test. EDIT: Dang, too many phone calls while I was typing a answer. Ninja! By the way, you should get rid of ALL your GoTo's, they are not something you want to use in your code. Gosubs or functions, or anything else, just not the dreaded GoTo. |
||
| Back to top |
|||
|
Rich Dersheimer
User ![]() Joined: Wed Jul 1st 2009 Location: Driving a Mark 4 Mod 5 Badger Hovertank! |
Something like this might work better... + Code Snippet where each question has its own little loop that only ends when the correct answer is input. That way your program logic falls straight through, and is much easier to understand and debug. |
||
| Back to top |
|||
|
Daniel wright 2311
User ![]() Joined: Sat Dec 22nd 2007 Location: pueblo, colorado |
|
||
| Back to top |
|||
|
Grog Grueslayer
User ![]() Joined: Mon May 30th 2005 Location: Darkbasic Pro |
I would of thought that N3wton would make sure you were taught the evils of using GOTO. Using LOCAL outside of functions is pretty much useless since anything not defined as GLOBAL can't be used in functions anyway. Using $ in a variable tells Darkbasic you want a string... there's no need to tell it "as string" if you use a $ in the name. You also shouldn't be using data$ since DATA is a command. Any time you get user input you need to convert the string to either all higher case letters or all lower case letters. If you don't do that the user would have to write in exactly the same case you're checking for. If (as the way you wrote it) you check for "Correlation" and the user writes down "correlation" it won't detect it because they didn't use an upper case C. I personally would just throw it all into an array and use one routine to do all the questions: + Code Snippet |
||
| Back to top |
|||
You must be logged-in to post messages to this forum. You can register an account for free. Or click here to login.
Forum Search
Enter a word or phrase to search our Forum for:
|
|









