
-----------------------------------
ThePress_Dog
Wed Nov 02, 2011 8:26 am

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.

-----------------------------------
Nick
Wed Nov 02, 2011 8:30 am

RE:Help making bulletproof turing program
-----------------------------------
Look into strint and strintok. Also you may also need to declare a couple temp variables.

-----------------------------------
ThePress_Dog
Wed Nov 02, 2011 8:35 am

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
Wed Nov 02, 2011 8:54 am

RE:Help making bulletproof turing program
-----------------------------------
Why is this not in one of the Turing forums?

-----------------------------------
ThePress_Dog
Wed Nov 02, 2011 8:56 am

Re: Help making bulletproof turing program
-----------------------------------
Because i am an absolute noob at this site :D Sorry about that, i just needed a reply really quick and saw " General Discussion " and "Programming questions " etc.

-----------------------------------
tg851
Wed Nov 02, 2011 10:41 am

RE:Help making bulletproof turing program
-----------------------------------
look into ord and chr for turning numbers into characters and vice-versa

-----------------------------------
Velocity
Sun Nov 06, 2011 1:21 pm

RE:Help making bulletproof turing program
-----------------------------------
What do you mean by bullet proof? I may be able to help.

-----------------------------------
Beastinonyou
Sun Nov 06, 2011 3:40 pm

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:


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


-----------------------------------
tg851
Mon Nov 07, 2011 11:21 am

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:


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
Mon Nov 07, 2011 2:07 pm

Re: Help making bulletproof turing program
-----------------------------------

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.
