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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone helps me?

Status
Not open for further replies.

mobilef

IS-IT--Management
Sep 30, 2005
10
HK
I typed a pascal program. I run the it(exe file),and I input a string to a integer varible, the proram will error and exit, how can i solve it?
I am using Free Pascal.
 

Assuming you are expecting the user to enter an integer, the best way is to define the variable as a string. After it has been entered, check whether the string is actually an integer and then convert it to an integer variable.
 
But it will make the program more complicated.
Are there any better methods?
 
But it will make the program more complicated.
are there any better methods?

If you're wanting a good solid program, you're going to be doing what stackdump said. Error checking is ALWAYS the way to do things.

Besides, why can't you make this into a function that returns the integer value and doesn't exit until the user puts in a valid value?
 

mobilef, I guess you're new to programming?, so perhaps I can give you some hints. I'm afraid that posting solutions to users problems is not the done thing on these forums, otherwise the user will miss out on the learning experience, but here's a little help.

Look up the statements "FUNCTION", "WHILE", "READLN", "LENGTH", and "IN" in a good text book. Using these statements together with some IF THEN statements, you can make a function that will do what you want.

Whenever you write a program, never assume the user will type in what you expect! Error checking makes software a little more complicated but a lot more robust.




 
Could anyone give me a sample?
My pascal is not so good.
Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top