The Game Creators
The Game Creators Home Online Shop Click to Login
  Hot: Christmas CompetitionNovember NewsletterModel Pack 36DB Pro Pack 2009DGS BonanzaCharacter PackFPS Creator Bonanza;
The Game Creators
DBPro Newcomers / No idea what i've done wrong...

Go to the first page of this board Return to the Forum Menu Post Message
8 Messages - Page   of 1   
Bookmark and Share Search the Forum

Author Message
TillyLala

User


Joined: Mon Jul 6th 2009
Location: In the little cupboard under the stairs
Posted: 4th Nov 2009 15:24           | link | toggle

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
local hypothesis$ as string
local expdes$ as string
local data$ as string

Start:

Input "What was the hypothesis? ", hypothesis$

If hypothesis$ = "Correlation"
	Print "Use Spearmans Rho"
	wait key
	CLS
	endif
	GoTo Start
	

If hypothesis$ = "Difference"
	Print "Check experimental design"
	wait key
	CLS
	endif
	GoTo Start
	
Wait key 
Print " " 

Input "What experimental design was used? ", expdes$

If expdes$ = "Independant measures"
	Print "Use mann-whitney u"
	Wait Key
	CLS
	endif
	GoTo Start
	

If expdes$ 	= "Repeated Measures"
	Print "Wilcoxon Test"
	Wait Key
	CLS
	endif
	GoTo Start
	
Wait key 
Print " "

Input "What kind of data was used? ", data$

If data$ = "Nominal"
	Print "Chi Squared"
	Wait Key 
	CLS
	GoTo Start	
Endif


Back to top
Report this message as abusive
Daniel wright 2311

User


Joined: Sat Dec 22nd 2007
Location: pueblo, colorado
Posted: 4th Nov 2009 15:43     Edited: 4th Nov 2009 15:46     | link | toggle

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
Report this message as abusive
Satchmo

User


Joined: Sun May 29th 2005
Location: Cyberspace
Posted: 4th Nov 2009 15:46           | link | toggle

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
local hypothesis$ as string
local expdes$ as string
local data$ as string

Start:

Input "What was the hypothesis? ", hypothesis$

If hypothesis$ = "Correlation"
	Print "Use Spearmans Rho"
	wait key
	CLS
        GoTo Start	
        endif
	
	

If hypothesis$ = "Difference"
	Print "Check experimental design"
	wait key
	CLS
        GoTo Start
	endif

If hypothesis$ = CORRECT ANSWER HERE"
	Print "Correct!"
	wait key
	CLS
        GoTo NextQuestion
	endif	
GoTo Start
NextQuestion:

Wait key 
Print " " 

Input "What experimental design was used? ", expdes$

If expdes$ = "Independant measures"
	Print "Use mann-whitney u"
	Wait Key
	CLS
	GoTo Start
	endif


If expdes$ 	= "Repeated Measures"
	Print "Wilcoxon Test"
	Wait Key
	CLS
	GoTo Start
	endif

	
Wait key 
Print " "

Input "What kind of data was used? ", data$

If data$ = "Nominal"
	Print "Chi Squared"
	Wait Key 
	CLS
	GoTo Start	
Endif


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
Report this message as abusive
TillyLala

User


Joined: Mon Jul 6th 2009
Location: In the little cupboard under the stairs
Posted: 4th Nov 2009 15:51           | link | toggle

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:

Back to top
Report this message as abusive
Google Ad
Back to top
 
Rich Dersheimer

User


Joined: Wed Jul 1st 2009
Location: Driving a Mark 4 Mod 5 Badger Hovertank!
Posted: 4th Nov 2009 15:58     Edited: 4th Nov 2009 16:00     | link | toggle

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
Quickhack Developer Journal
Report this message as abusive
Rich Dersheimer

User


Joined: Wed Jul 1st 2009
Location: Driving a Mark 4 Mod 5 Badger Hovertank!
Posted: 4th Nov 2009 16:09           | link | toggle

Something like this might work better...
+ Code Snippet
while a$<>"Correct Answer"
  input "What was...", a$
  if a$="Correlation" then print "Use Spearmans Rho"
  if a$="Difference" then print "Check experimental design"
endwhile
print "Correct!"

while a$<>"Correct Answer #2"
  input "What experimental design was used?", a$
  if a$="Independant measures" then print "Use Mann-Whitney U"
  if a$="Repeated Measures" then print "Wilcoxon Test"
endwhile
print "Correct!"


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
Quickhack Developer Journal
Report this message as abusive
Daniel wright 2311

User


Joined: Sat Dec 22nd 2007
Location: pueblo, colorado
Posted: 4th Nov 2009 16:18     Edited: 4th Nov 2009 16:20     | link | toggle

here is a easy way

+ Code Snippet
local hypothesis$ as string
local expdes$ as string
local data$ as string

Start:
s1=0
Input "What was the hypothesis? ", hypothesis$

If hypothesis$ = "Correlation"
s1=1
endif


if s1=1
   Print "Use Spearmans Rho"
endif

  if wait key()=1
   CLS
   GOSUB Start2
   endif


DSW
Back to top
Report this message as abusive
Grog Grueslayer

User


Joined: Mon May 30th 2005
Location: Darkbasic Pro
Posted: 5th Nov 2009 08:59           | link | toggle

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
` Dimensionalize the array
dim Question$(50,4)
` Question$(xx,0) - The Question
` Question$(xx,1) - Answer #1
` Question$(xx,2) - Output #1
` Question$(xx,3) - Answer #2
` Question$(xx,4) - Output #2

Question$(0,0)="What was the hypothesis? "
Question$(0,1)="CORRELATION"
Question$(0,2)="Use Spearmans Rho"
Question$(0,3)="DIFFERENCE"
Question$(0,4)="Check experimental design"

Question$(1,0)="What experimental design was used? "
Question$(1,1)="INDEPENDANT MEASURES"
Question$(1,2)="Use mann-whitney u"
Question$(1,3)="REPEATED MEASURES"
Question$(1,4)="Wilcoxon Test"

Question$(2,0)="What kind of data was used? "
Question$(2,1)="NOMINAL"
Question$(2,2)="Chi Squared"

do

 ` Go through all the questions
 for CQuest=0 to 2
 
  cls
 
  ` Get the user input
  input Question$(CQuest,0),a$

  ` Convert a$ to all higher case letters (to check answer easier)
  a$=upper$(a$)

  ` Look at both answers in the array (look at #1, skip #2, look at #3)
  for Answer=1 to 3 step 2

   ` Check if a$ matches the first or second answer
   if a$=Question$(CQuest,Answer)
    ` Print the output
    print Question$(CQuest,Answer+1) 
   endif

  next Answer

  wait key

 next CQuest

loop


Back to top
Grog\'s Grotto
Report this message as abusive

Go to the first page of this board Return to the Forum Menu Post Message
8 Messages - Page   of 1   
Search the Forum

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:

Thread Subject Search
Search Phrase:
Search Scope: Entire forum
Just this board
 
Google Forum Search
Search Phrase:
 
Apollo v2.02


Dark Game Studio
Privacy Policy AUP Top of Page