•
•
•
•
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
![]() |
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.•
•
Join Date: Jun 2006
Location: Blumenau, Brazil
Posts: 67
Reputation:
Rep Power: 3
Solved Threads: 4
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
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
Brazil - Blumenau
•
•
Join Date: Dec 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Error msg ' Operation Aborted' when accessing some websites. (Web Browsers)
- Pascal : How to display an error msg when integer entered for a name? (Pascal and Delphi)
- problems with Windows 2000 professional. "Systemced" error msg (Windows NT / 2000 / XP / 2003)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Pascal 200 Error
- Next Thread: data modules


Linear Mode