Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 NEED HELP WITH HW PLEASE!!!!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
countergary




PostPosted: Tue Jan 25, 2005 5:59 pm   Post subject: NEED HELP WITH HW PLEASE!!!!!

Hey guys watsup, im new here!!! Very Happy

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!!! Crying or Very sad
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

Smile
Sponsor
Sponsor
Sponsor
sponsor
cool dude




PostPosted: Tue Jan 25, 2005 6:21 pm   Post subject: (No subject)

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.

code:

% 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




PostPosted: Tue Jan 25, 2005 8:30 pm   Post subject: (No subject)

"% keep asking for input until it is a valid real"

to do this, u would need to use an if structure
basketball4ever




PostPosted: Wed Jan 26, 2005 1:17 am   Post subject: (No subject)

person wrote:
"% 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




PostPosted: Wed Jan 26, 2005 6:48 pm   Post subject: (No subject)

i know but im just giving another option Very Happy
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: