Just trying to make my program user friendly...but I get the response 'Wrong' when I enter in a number or abcd when really I want my error message displayed when the user enters input like that and ONLY a Correct or Wrong response when the user enters 'A' 'B' 'C' or 'D', any ideas?

Program Quiz;
uses crt;

Var
        Quizfile : Text;
        Line : String;
        answer : Char;
        I, Money, Score : Integer;

Begin
     clrscr;
     Money :=0;
     Score :=0;
     Assign(Quizfile, 'E:\test.dat');
     Reset (Quizfile);
     While not EOF (Quizfile) DO
     Begin
       FOR I:= 1 TO 5 DO
       Begin
           Readln(Quizfile, line);
           Writeln(line);
       End;
       Readln(Quizfile, line);
       Repeat
       Writeln('Please enter the letter you think is correct');
       Readln(answer);
       IF UPCASE(answer) = line THEN
       Begin
          Writeln('Correct');
          Money := Money +5;
          Score := Score +1;
       End
        ELSE IF (UPCASE(answer) <=UPCASE('a'))
       OR (UPCASE(answer) <=UPCASE('b'))
       OR (UPCASE(answer) <=UPCASE('c'))
       OR(UPCASE(answer) <=UPCASE('d')) THEN
           Begin
             Writeln('Wrong');
             Money := Money-5;
             Score := 0+Score;
           End
           ELSE
           Begin
            Writeln('Only A,B,C or D are options!!!!');
            End;
            Until (UPCASE(answer) <=UPCASE('a'))
       OR (UPCASE(answer) <=UPCASE('b'))
       OR (UPCASE(answer) <=UPCASE('c'))
       OR(UPCASE(answer) <=UPCASE('d'));
        Writeln('Money Won is £', money);
        Writeln('Score out of 12 questions is ', score);
        Writeln('Please press Return');
        Readln;
        clrscr;
       End;
       Close (Quizfile);
End.
Member Avatar for Micheus

adotl, in order to get only a character on input for this:
Writeln('Please enter the letter you think is correct');
Readln(answer);
take a look on ReadKey function in help and replace than to Readln - in this moment I can't remember how to explane you about it, sorry.

Just a tip: make no sence use this sentence like you put that:
IF (UPCASE(answer) <=UPCASE('a'))...
use by this way:
IF (UPCASE(answer) <='A')...

bye

thanks for the reply, I'll look into making these changes!!!

I think U could refine ur program a bit. Since u set the condition in this line [IF UPCASE(answer) = line ] then everythig else must be incorrect and u could eliminate all the Boolean OR statements up to the error message. U could also refine the repeat loop to something like Until Upcase (answer) in and eliminate the other set of Boolean statements

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.