
-----------------------------------
countergary
Tue Jan 25, 2005 5:59 pm

NEED HELP WITH HW PLEASE!!!!!
-----------------------------------
Hey guys watsup, im new here!!! :D 

Anyways, you see im having this big Isu due in a few days and I need 

help badly!!!!

My problem is Error proofing my program!!! :cry: 
You see, I want my program to catch numbers and other different command's that would normaly make the program crash, and I have no clue of how to do that. Could someone help me please or at lease post an tutorial on how to error proof properly. 

Thank You

 :)

-----------------------------------
cool dude
Tue Jan 25, 2005 6:21 pm


-----------------------------------
firstly there are a lot of tutorials on error proofing but if u can't read them then i'll just give it to u. this is a function that the error proofing is written in and all u have to do is call it in your main program where u ask the user to enter something and it will work. put this on top of your program.


% function to find a valid integer
function validint : int
    var input : string % user's input - can be anything

    get input

    % keep asking for input until it is a valid integer
    loop
        exit when strintok (input)
        put "not a valid integer, try again"
        get input
    end loop

    % send the valid integer to the main program
    result strint (input)
end validint




% function to find a valid integer
function validreal : real
    var input : string % user's input - can be anything

    get input

    % keep asking for input until it is a valid real
    loop
        exit when strrealok (input)
        put "not a valid real number, try again"
        get input
    end loop

    % send the valid real number to the main program
    result strreal (input)
end validreal
% Main program

% Declare variables
var num : int   % valid integer
var num2 : real % valid real

% Ask for input
put "please enter an integer"
num := validint
put "please enter a real number"
num2 := validreal


i didn't have a lot of time to make a really good error proofing program but this works. unless u enter ctrl z then it will crash but i don't really know how to error proof that

-----------------------------------
person
Tue Jan 25, 2005 8:30 pm


-----------------------------------
"% keep asking for input until it is a valid real"

to do this, u would need to use an if structure

-----------------------------------
basketball4ever
Wed Jan 26, 2005 1:17 am


-----------------------------------
"% keep asking for input until it is a valid real"

to do this, u would need to use an if structure

you only need an if structure if you want a message popping up to the user... the code above works perfectly fine.  The loop will exit the same way as a normal if structure

-----------------------------------
person
Wed Jan 26, 2005 6:48 pm


-----------------------------------
i know but im just giving another option :D
