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

Username:   Password: 
 RegisterRegister   
 Help making bulletproof turing program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ThePress_Dog




PostPosted: Wed Nov 02, 2011 8:26 am   Post subject: Help making bulletproof turing program

Hi!
I was given an assignment by my teacher to make a simple Turing program, but it has to be bulletproof. I have to get 2 numbers from the user and output the sum and product however, it cannot crash if the user enters a alphabetic value. Here is my code so far
var num1, num2 : real
loop
put " Choose a number, any number. "
get num1
put " Again, enter a number different from the first. "
get num2

put " The sum of your two numbers are : ", num1 + num2, " The product of your numbers are " , num1*num2
end loop
as you can see it is simple, but i cannot find the functions/ don't know how to use them to make this bulletproof (PS this is my first year of Programing)

Thank you.
Sponsor
Sponsor
Sponsor
sponsor
Nick




PostPosted: Wed Nov 02, 2011 8:30 am   Post subject: RE:Help making bulletproof turing program

Look into strint and strintok. Also you may also need to declare a couple temp variables.
ThePress_Dog




PostPosted: Wed Nov 02, 2011 8:35 am   Post subject: Re: Help making bulletproof turing program

I don't know where to put the functions either, and how to declare a temporary value, we only learned the built in functions yesterday.
md




PostPosted: Wed Nov 02, 2011 8:54 am   Post subject: RE:Help making bulletproof turing program

Why is this not in one of the Turing forums?
ThePress_Dog




PostPosted: Wed Nov 02, 2011 8:56 am   Post subject: Re: Help making bulletproof turing program

Because i am an absolute noob at this site Very Happy Sorry about that, i just needed a reply really quick and saw " General Discussion " and "Programming questions " etc.
tg851




PostPosted: Wed Nov 02, 2011 10:41 am   Post subject: RE:Help making bulletproof turing program

look into ord and chr for turning numbers into characters and vice-versa
Velocity




PostPosted: Sun Nov 06, 2011 1:21 pm   Post subject: RE:Help making bulletproof turing program

What do you mean by bullet proof? I may be able to help.
Beastinonyou




PostPosted: Sun Nov 06, 2011 3:40 pm   Post subject: Re: Help making bulletproof turing program

by "Bulletproof", it's simply a term used to describe having a program not be able to be crashed by something a user does.

In this case, he needs to ensure that when the user enters num1 and num2, they are in fact only integers. if they contain an alphanumeric value, it will crash.

Use this to help solve your problem:

Turing:

var num1, num2 : string

loop
    put "Enter First Number: " ..
    loop
        get num1
        exit when strintok (num1)
    end loop
    put "Enter Second Number: " ..
    loop
        get num2
        exit when strintok (num2)
    end loop
    put "The Sum of the two numbers you've entered is: ", strint (num1) * strint (num2)
end loop
Sponsor
Sponsor
Sponsor
sponsor
tg851




PostPosted: Mon Nov 07, 2011 11:21 am   Post subject: Re: Help making bulletproof turing program

Beastinonyou @ Sun Nov 06, 2011 3:40 pm wrote:
by "Bulletproof", it's simply a term used to describe having a program not be able to be crashed by something a user does.

In this case, he needs to ensure that when the user enters num1 and num2, they are in fact only integers. if they contain an alphanumeric value, it will crash.

Use this to help solve your problem:

Turing:

var num1, num2 : string

loop
    put "Enter First Number: " ..
    loop
        get num1
        exit when strintok (num1)
    end loop
    put "Enter Second Number: " ..
    loop
        get num2
        exit when strintok (num2)
    end loop
    put "The Sum of the two numbers you've entered is: ", strint (num1) * strint (num2)
end loop


I broke it,some unicode characters can make it go nighty night,but still its pretty damn sturdy
Zren




PostPosted: Mon Nov 07, 2011 2:07 pm   Post subject: Re: Help making bulletproof turing program

tg851 @ Mon Nov 07, 2011 11:21 am wrote:

I broke it,some unicode characters can make it go nighty night,but still its pretty damn sturdy


That has to do with limitations in Turing's character data type. It only accepts values in the ASCII range (0, 255). Strings are just arrays of characters, which is the data type use by the get statement.
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  [ 10 Posts ]
Jump to:   


Style:  
Search: