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 / No idea what i've done wrong...

Author
Message
TillyLala
15
Years of Service
User Offline
Joined: 6th Jul 2009
Location: In the little cupboard under the stairs
Posted: 4th Nov 2009 22:24
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



Daniel wright 2311
User Banned
Posted: 4th Nov 2009 22:43 Edited at: 4th Nov 2009 22:46
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
Satchmo
19
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 4th Nov 2009 22:46
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.



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)

TillyLala
15
Years of Service
User Offline
Joined: 6th Jul 2009
Location: In the little cupboard under the stairs
Posted: 4th Nov 2009 22:51
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 Thank you Have a beer:

Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 4th Nov 2009 22:58 Edited at: 4th Nov 2009 23:00
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.

Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 4th Nov 2009 23:09
Something like this might work better...


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.

Daniel wright 2311
User Banned
Posted: 4th Nov 2009 23:18 Edited at: 4th Nov 2009 23:20
here is a easy way



DSW
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 5th Nov 2009 15:59
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:


Login to post a reply

Server time is: 2024-11-24 00:38:36
Your offset time is: 2024-11-24 00:38:36