RSS Forums RSS
Please support our Pascal and Delphi advertiser: Programming Forums

Pascal : Refining an error msg.

Join Date: Apr 2007
Location: Glasgow
Posts: 32
Reputation: adotl is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
adotl's Avatar
adotl adotl is offline Offline
Light Poster

Help Pascal : Refining an error msg.

  #1  
Apr 25th, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:38 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC