Qbasicnews.com

Full Version: HELP ME PLZ ?!?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I am writing a simple 10 question true or false program.

The thing tells me script is out of range?
Not sure what that means.

Also, what am I doing wrong not to get the questions in the data statement to appear on screen?

This is what I have so far:

CLS

COLOR 2

max = 10

DIM question$(max)

FOR count = 1 TO 10
READ question$(count)
question$(count) = UCASE$(question$(count))
NEXT count

Start:

INPUT "Answer <T>rue or <False> ", answer$

PRINT question$(count)
PRINT question$(count)
PRINT question$(count)
PRINT question$(count)
PRINT question$(count)
PRINT question$(count)
PRINT question$(count)
PRINT question$(count)
PRINT question$(count)
PRINT question$(count)


LET T = 1
LET F = 0
FOR L = 1 TO max
LET all = T + F
NEXT L
LET AV% = all / 10
COLOR 4
PRINT "The Average is "; AV%
PRINT
END







DATA "The sky blue "
DATA "Rain is wet "
DATA "Snow is cold "
DATA "QB only stands for quarterback "
DATA "All trucks have 18 wheels "
DATA "All women nag "
DATA "Everyone has somekind of addiction "
DATA "Al Bundy scored 4 touchdowns in a high school football game "
DATA "All New Jersey people drive on the left side of the road "
DATA "QBasic is fun "

Cry :???: Cry :???: :x
question$(count),

you have 10 PRINT statements PRINTing question(count) out. However, you don't reinitialize the count variable first. Hence, it most likely has the value of 11 (which is what caused the FOR/NEXT loop to terminate). 11 is one more than the dimensionallity of your array. Hence, you get a "Subscript out of range" error. Possibly, what you really want to do here is replace your 10 PRINT statements with something like

FOR count = 1 to 10
PRINT question$(count)
next count
O.K. --I revised it a little and now the questions show (like you said)but the program will not take any input togive an answer of true or false?
What am I missing?

Revised as follows:


CLS

COLOR 2

max = 10

DIM question$(max)

FOR count = 1 TO 10
READ question$(count)
PRINT question$(count)
NEXT count

DO
Start:
PRINT
PRINT
INPUT "Answer <T>rue or <False> ", answer$


IF answer = 0 THEN
END
END IF

IF answer = correct THEN
PRINT " You are correct "
correct = correct + 1
GOSUB totals
END IF

IF answer = wrong THEN
PRINT " Sorry, you are wrong "
wrong = wrong + 1
GOSUB totals
END IF

att = att + 1
correct = correct + 1
wrong = wrong + 1
percent = correct / att


totals:
COLOR 4
PRINT " Total questions attempted "; att
PRINT " Total # correct "; correct
PRINT " Total # wrong "; wrong
PRINT " % correct "; percent

LOOP



DATA " 1 - The sky blue? "
DATA " 2 - Rain is wet? "
DATA " 3 - Snow is cold? "
DATA " 4 - QB only stands for quarterback? "
DATA " 5 - All trucks have 18 wheels? "
DATA " 6 - All women nag? "
DATA " 7 - Everyone has somekind of addiction? "
DATA " 8 - Al Bundy scored 4 touchdowns in a high school football game? "
DATA " 9 - All New Jersey people drive on the left side of the road? "
DATA "10 - QBasic is fun? "
LINE INPUT "Answer <T>rue or <False> ?"; answer$

instead of

INPUT "Answer <T>rue or <False> ", answer$


(LINE INPUT doesn't automatically supply the "?", so I changed the "," to ";".)
Well, I changed the way I had it written and still nothing.
Where do the answers need to be? In a data statement also?

This is what I added: changes are in color


CLS

COLOR 2

max = 10

DIM question$(max)
DIM answers$(count)


FOR count = 1 TO 10
READ question$(count)
PRINT question$(count)
NEXT count

start:
PRINT
PRINT
LINE INPUT "Answer <T>rue or <F>alse? ", answer$

answer$ = UCASE$(answer$)


DO
att = att + 1
correct = correct + 1
wrong = wrong + 1
percent = correct / att


IF answer = 0 THEN
END
END IF

IF answer = correct THEN
PRINT " You are correct "
correct = correct + 1
GOSUB totals:
END IF

IF answer = wrong THEN
PRINT " Sorry, you are wrong "
wrong = wrong + 1
GOSUB totals:
END IF


totals:
COLOR 4
PRINT " Total questions attempted "; att
PRINT " Total # correct "; correct
PRINT " Total # wrong "; wrong
PRINT " % correct "; percent

LOOP



DATA " 1 - The sky blue? "
DATA " 2 - Rain is wet? "
DATA " 3 - Snow is cold? "
DATA " 4 - QB only stands for quarterback? "
DATA " 5 - All trucks have 18 wheels? "
DATA " 6 - All women nag? "
DATA " 7 - Everyone has somekind of addiction? "
DATA " 8 - Al Bundy scored 4 touchdowns in a high school football game? "
DATA " 9 - All New Jersey people drive on the left side of the road? "
DATA "10 - QBasic is fun?

DATA " 1 is True "
DATA " 2 is True "
DATA " 3 is True "
DATA " 4 is False "
DATA " 5 is False "
DATA " 6 is True "
DATA " 7 is False "
DATA " 8 is True "
DATA " 9 is True "
DATA "10 is True "
ask for a single answer. But there's no indication of which question that answer applies to. And then you test a *numeric* variable "answer" against numeric values. What's "answer"? Also, you do

ATT = ATT + 1

inside of a DO LOOP but you don't initialize ATT anywhere before that loop. You might want to avoid just assuming that ATT starts out at zero. 1) As your program grows, you may find incrementation (or other) variables changing from what you assumed its initial value to be and 2) if you move on to programming on other types of computers and other languages, you may likely find that undefined variables don't necessarilly start out at zero. (They start out at whatever number is constituted by the set of bytes that just happen to be in memory at the location of the variable in question.)


Try this. (Feel free to adjust the answers I put in the DATA statement at the end, or anything else you want.)




CLS

COLOR 2


DIM MAX AS INTEGER,QUEST AS INTEGER,ATT AS INTEGER,CORRECT AS INTEGER
DIM WRONG AS INTEGER
max = 10

DIM question$(max),answers$(count),KNOWN$(MAX)


FOR count = 1 TO MAX
READ question$(count)
NEXT count
FOR COUNT=1 TO MAX
READ KNOWN$(COUNT)
NEXT COUNT
ATT=0
CORRECT=0
WRONG=0
FOR COUNT=1 TO MAX
'
' You shouldn't need to track ATT here. It's equal to MAX.
'
att = att + 1
PRINT
PRINT
PRINT question$(count)
PRINT
PRINT
LINE INPUT "Answer <T>rue or <F>alse? ", answer$

answer$ = LEFT$(UCASE$(LTRIM$(answer$)),1)
IF ANSWER$<>KNOWN$(COUNT) THEN GOTO WRONG
'
' Right answer. Update CORRECT counter.
'
PRINT
PRINT "You are correct."
CORRECT=CORRECT+1
GOTO GOON:
WRONG:
'
' Wrong answer. Update WRONG counter.
'
PRINT "You are wrong."
WRONG=WRONG+1
GOON:
NEXT COUNT
'
' Display statistics.
'
PRINT
PRINT
percent = 100!*correct / att
PRINT " Total questions attempted "; att
PRINT " Total # correct "; correct
PRINT " Total # wrong "; wrong
PRINT " % correct "; percent
END
DATA " 1 - The sky blue? "
DATA " 2 - Rain is wet? "
DATA " 3 - Snow is cold? "
DATA " 4 - QB only stands for quarterback? "
DATA " 5 - All trucks have 18 wheels? "
DATA " 6 - All women nag? "
DATA " 7 - Everyone has somekind of addiction? "
DATA " 8 - Al Bundy scored 4 touchdowns in a high school football game? "
DATA " 9 - All New Jersey people drive on the left side of the road? "
DATA "10 - QBasic is fun?
DATA "T","T","T","F","F","T","T","T","F","F"
Thank you very much for helping me get this to work
.
not to pretend anything, but wouldn't it be much more simple if you use something like:

for i=1 to 4
PRINT "Correct: "; correct, "Wrong: "; wrong, "Total: " wrong+correct
read a$:read b
PRINT a$
giveanswer: LINE INPUT "<t>rue <f>alse??"; answer$
IF answer$="t" then c=1
IF answer$="f" then c=2
if answer$<>"f" and answer$<>"t"then PRINT "choose a t or an f": goto giveanswer: END IF
if c=b then
correct=correct+1
PRINT "That's right!"
END IF
if c<>b then
wrong=wrong+1
PRINT "Too bad...."
END IF
next i

DATA rain is wet?,1
DATA skies are blue?,1
DATA I am nuts?,1
DATA Is Antananarivo the capital of Mali?,2
Glenn: couldn't you have put a DEFINT A-Z line at the top of your prog instead of all those DIM whatever AS INTEGERs?

I am probably missing something here, but hey.
Pages: 1 2