
-----------------------------------
Jas
Mon Mar 28, 2005 1:52 am

if answer not = integer then?
-----------------------------------
Im doing a project, and my teacher said you have to make your program error trapped. So, i have a program where the user types an integer, and the program runs, but if he types anything else, it crashes. how do u error trap this? im asking for something like this...

var ans: int
get ans
if answer > 0 then
     %continue with program
else ans not = int then
     put "invalid input"
end if


the "else ans not = int then" line doesn't work, I just made it up so you will understand what im taking about. so what can i do to this program so it doesn't crash when the user types anything but an integer?

p.s. how do u put the "code" thing on top of your program? I saw other programs that people posted, and they had that word on top of them. why do u need that?

-----------------------------------
Mr. T
Mon Mar 28, 2005 2:32 am


-----------------------------------
[ code][/code ]
put ur code in between those tags. (but without the spaces in the [ ] brackets)

as for your int problem...as far as i know, that wont work because int is an identifier, and ur setting it as a condition. so really i have no solution  :oops:

-----------------------------------
Cervantes
Mon Mar 28, 2005 6:11 am


-----------------------------------
String manipulation.  I just remembered I'm going to write a tutorial on it soon, so if you don't know much about it, look for that.

var input : string
var num : int
get input
if strintok (input) then
    num := strint (input)
end if


-----------------------------------
Mr. T
Mon Mar 28, 2005 8:06 am


-----------------------------------
ok, listen to cervantes, he knows best   :lol:

-----------------------------------
Mazer
Mon Mar 28, 2005 9:29 am


-----------------------------------
You may also want to put that in a loop with a message to the user, as the rest of the program probably relies on the variable:

var input : string
var num : int
get input
loop
    exit when strintok (input)
    put "Invalid input, please try again:"
    get input
end loop
num := strint (input)


-----------------------------------
Jas
Mon Mar 28, 2005 12:06 pm


-----------------------------------
I see how this works. I decided to use something like this:



var input : string
var num : int
loop
    get input
    if strintok (input) then
        num := strint (input)
    else
        put "Invalid input"
    end if
end loop



thx for the help.

-----------------------------------
Mazer
Mon Mar 28, 2005 12:09 pm


-----------------------------------
Don't forget to exit the loop once you've got a valid input!

-----------------------------------
Naveg
Mon Mar 28, 2005 5:44 pm


-----------------------------------
I see how this works. I decided to use something like this:



var input : string
var num : int
loop
    get input
    if strintok (input) then
        num := strint (input)
        exit
    else
        put "Invalid input"
    end if
end loop



thx for the help.

there i added a line, dont forget it its important
