0

I am writing a program (well, actually I have finished it) using pascal, the program is to read in 3 sides of the triangle and produce a message whether it is right-angled, iscosceles, obtuse etc. Now just to finish it off and make it user friendly i need some sort of function that will check whether the data entered is numeric not letters. If it is letter then it should say "Please re-enter the number" and read it in again.

Thanks in advance.

3
Contributors
5
Replies
8
Views
9 Years
Discussion Span
Last Post by adotl
0

Sorry for double posting, the browser crashes when i try to edit my post. I think there shouldnt be any problems with decimals, but the program must show the error message if comma or any symbol is entered too.

0

I had this same problem recently and discovered that in pascal there is a 'Val' function (with 3 parameters, 1st for the string, second for integer and third for error message if the 1st parameter is true) for converting a number into a string....your program would work like this...

Repeat
         write('What is the triangle''s height? ');
         readln(h_string);
         val(h_string, h, Err);
         if Err > 0 then
            writeln('An illegal character was found at character #', Err, '.')
         else if h <= 0 then
            writeln('The height needs to be GREATER than zero.')
      Until (h > 0) AND (Err = 0);
0

i think you can :
//letter is char of input
case letter of
'0'..'9':
//put error handler here
else
//normal code
end;

or you can check after input complete:
for i:= 1 to Length(strInput) do
if strInput in = false then
begin
//put eror handler here
end;

0

thanks for your help

actually adotl your VAL function is really great, it works for me and now I will (with a bit of luck) pass my IT course :) again thanks so much

0

thanks for your help

actually adotl your VAL function is really great, it works for me and now I will (with a bit of luck) pass my IT course :) again thanks so much

No problem mate!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.