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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.