All pastes #494467 Raw Edit

CCFreak2K

public text v1 · immutable
·published 2007-05-18 08:22 UTC
rendered paste body
CLS
PRINT "Author: Wendy Booth"
PRINT " Welcome to my quiz!"
DIM Question AS STRING
DIM CorrectAnswer AS STRING
DIM Option1 AS STRING
DIM Option2 AS STRING
DIM Option3 AS STRING
DIM Option4 AS STRING
DIM RecordTerminator AS STRING
DIM Guess AS STRING
DIM NumCorrect AS INTEGER
DIM NumQuestions AS INTEGER
DIM PercentCorrect AS INTEGER
OPEN "quiz.txt" FOR INPUT AS #1
        DO WHILE NOT EOF(1)
                INPUT #1, Question
               ' INPUT #1, CorrectAnswer
                PRINT Question;
               ' PRINT Option1;
                PRINT Option2;
               ' PRINT Option3;
               ' PRINT Option4;
                NumQuestions = NumQuestions + 1
                INPUT "Answer? ", Guess
                IF Guess = CorrectAnswer THEN
                        NumCorrect = NumCorrect + 1
                        PRINT "Correct!"
                ELSE
                        PRINT "Incorrect"
                END IF
        LOOP
CLOSE #1
PRINT "End of quiz"
PRINT "Total number of questions"; NumQuestions
PercentCorrect = (NumCorrect / NumQuestions) * 100
PRINT "You answered"; NumCorrect; "questions correctly"
PRINT "Your percentage is"; PercentCorrect



quiz.txt is this
CLS
PRINT "Author: Wendy Booth"
PRINT " Welcome to my quiz!"
DIM Question AS STRING
DIM CorrectAnswer AS STRING
DIM Option1 AS STRING
DIM Option2 AS STRING
DIM Option3 AS STRING
DIM Option4 AS STRING
DIM RecordTerminator AS STRING
DIM Guess AS STRING
DIM NumCorrect AS INTEGER
DIM NumQuestions AS INTEGER
DIM PercentCorrect AS INTEGER
' Null value to handle breaks in the quiz file
DIM QuizBreak AS STRING
OPEN "quiz.txt" FOR INPUT AS #1
        DO WHILE NOT EOF(1)
                INPUT #1, Question
                INPUT #1, CorrectAnswer
                INPUT #1, Option1
                INPUT #1, Option2
                INPUT #1, Option3
                INPUT #1, Option4
                INPUT #1, QuizBreak
                PRINT Question;
                PRINT ""
                PRINT "1: "; Option1;
                PRINT ""
                PRINT "2: "; Option2;
                PRINT ""
                PRINT "3: "; Option3;
                PRINT ""
                PRINT "4: "; Option4;
                PRINT ""
                NumQuestions = NumQuestions + 1
                INPUT "Answer? ", Guess
                IF Guess = CorrectAnswer THEN
                        NumCorrect = NumCorrect + 1
                        PRINT "Correct!"
                ELSE
                        PRINT "Incorrect"
                END IF
        LOOP
CLOSE #1
PRINT "End of quiz"
PRINT "Total number of questions"; NumQuestions
PercentCorrect = (NumCorrect / NumQuestions) * 100
PRINT "You answered"; NumCorrect; "questions correctly"
PRINT "Your percentage is"; PercentCorrect