Please support our Pascal and Delphi advertiser: Programming Forums
Views: 2198 | Replies: 3 | Solved
I was doing some coding today and came across a problem someone else faced and I couldnt answer it for them. I'll explain the concept in the little program below....
...Basically what the programmer wanted to do was do an error message if a word or even a char was entered instead of a number so the program doesnt crash like how its setup now.
I started to think well an easy way would be if there was a variable type that stored both integer, char and string. But I dont think there is one?
So the only idea I had was to do an IF Else statement where ELSE displays the error message and asks the user to enter a number this time. However since the value here is stored as an integer I wasnt sure how to get around this.
Any ideas/help would be greatly appreciated.
Program between;
uses crt;
Var
value: integer;
Begin
clrscr;
writeln('Please enter value');
readln(value);
readln
End....Basically what the programmer wanted to do was do an error message if a word or even a char was entered instead of a number so the program doesnt crash like how its setup now.
I started to think well an easy way would be if there was a variable type that stored both integer, char and string. But I dont think there is one?
So the only idea I had was to do an IF Else statement where ELSE displays the error message and asks the user to enter a number this time. However since the value here is stored as an integer I wasnt sure how to get around this.
Any ideas/help would be greatly appreciated.
Last edited by adotl : Apr 24th, 2007 at 11:57 am.
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Threaded Mode