User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 402,905 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,146 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 906 | Replies: 3
Reply
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  
Join Date: Jun 2006
Location: Blumenau, Brazil
Posts: 67
Reputation: Micheus is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
Micheus's Avatar
Micheus Micheus is offline Offline
Junior Poster in Training

Re: Pascal : Refining an error msg.

  #2  
May 2nd, 2007
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
"It always has, at least, two ways to make one same thing. Exactly that they are certain and wrong"(Micheus)

Brazil - Blumenau
Reply With Quote  
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

Re: Pascal : Refining an error msg.

  #3  
May 2nd, 2007
thanks for the reply, I'll look into making these changes!!!
Last edited by adotl : May 2nd, 2007 at 6:54 pm.
Reply With Quote  
Join Date: Dec 2006
Posts: 2
Reputation: LennyC is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
LennyC LennyC is offline Offline
Newbie Poster

Re: Pascal : Refining an error msg.

  #4  
May 3rd, 2007
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 ['A', 'B', 'C', 'D'] and eliminate the other set of Boolean statements
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 3:29 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC