Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need Help with Delphi Please

Status
Not open for further replies.

12312366

Technical User
Mar 30, 2003
1
AU
Hi im New to Delphi and i need some help with a program i can't seem to get to compile;

procedure displayGrade(mark : integer);
begin
case mark of
0..49 : writeln('Fail');
50..64: writeln('Pass');
65..79: writeln('Credit');
80..100:writeln('Honours');
else
writeln('invalid entry');
end; //case
end;

var
Grade : integer;
begin
repeat
Write('Enter Grade or mark (-1 to stop) >');
readln(Grade);
if Grade <> stop then
displayGrade(Grade);
until Grade = stop
end.
Do you really need the &quot;case mark of&quot; statement or can it be changed to somthing different?
Thanks for your time :)
 
I think that when you use

readLn

you need to feed it a string variable, not an integer one

var
iGrade : integer;
sGrade: string;
begin
repeat
Write('Enter Grade or mark (-1 to stop) >');
readln(sGrade);
iGrade := StrToInt(sGrade);
if iGrade <> -1 then
displayGrade(iGrade);
until Grade = -1
end.

You will have to add some error handling on the strtoint line to avoid invalid user input.

var
iGrade : integer;
sGrade: string;
begin
repeat
Write('Enter Grade or mark (-1 to stop) >');
readln(sGrade);
try
iGrade := StrToInt(sGrade);
except
//do nothing, or write an error line, your choice...
end;
if iGrade <> -1 then
displayGrade(iGrade);
until Grade = -1
end.


If you still get errors read the compile messages, they are usually pretty good...

Andrew
 
The only thing I see stopping the compiler in the original is the lack of a definition of stop.

I've never had occasion to do a console app so I don't know if there's something needed in the uses that's not there.

The integer input works but is a bit dangerous--it will throw an exception if what's entered isn't a valid number.
 
Are you creating a console application ?
If not then why aren't you using any objects ?

Make the Grade variable a string and not a integer.
Pass the Grade as a integer to DisplayGrade by saying StrToInt.
How is stop declared ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top