Hi all, I have been creating a program that checks the length of an inputted value. The value inputted needs to be between two specific bounds, e.g. 10 < length < 120.
However, I want to ensure that an individual cannot enter text, or a value which is not between this range. At present the code I have looks like this:
program length;
uses
crt, sysutils;
var
number: string[9];
length: real;
begin
Clrscr;
Writeln('Please enter your the Length: ' );
writeln;
readln(number);
repeat
try
length := StrToFloat(number);
if (length < 10) or (length > 120) then
begin
Clrscr;
writeln('An error has occured. Please try again.');
writeln;
readln(number);
end;
except
clrscr;
writeln('An error has occured. Please try again.');
writeln;
readln(number);
end;
until (length >= 10) and (length <= 120);
clrscr;
Writeln('Your length is: ', length:0:2 );
readln;
end.
The code does not bring up any errors but it doesn't work the correct way either. If a user were to input text at first, it will bring up an error message. They then get to input a new value for the length. However when they input this value it doesn't work. It outputs the length as 0!
Please could someone help, feel free to rewrite the code :)
Thanks
Greg