Help making bulletproof turing program
Author |
Message |
ThePress_Dog
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Nick
![](http://compsci.ca/v3/uploads/user_avatars/19644337547e837b41d67a.png)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
ThePress_Dog
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
md
![](http://compsci.ca/v3/uploads/user_avatars/1849317514ed6c4399768d.png)
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
ThePress_Dog
|
Posted: Wed Nov 02, 2011 8:56 am Post subject: Re: Help making bulletproof turing program |
|
|
Because i am an absolute noob at this site Sorry about that, i just needed a reply really quick and saw " General Discussion " and "Programming questions " etc. |
|
|
|
|
![](images/spacer.gif) |
tg851
![](http://compsci.ca/v3/uploads/user_avatars/769939254ed665749ae13.jpg)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Velocity
![](http://compsci.ca/v3/uploads/user_avatars/1809397984eb9e2888e99b.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Beastinonyou
![](http://compsci.ca/v3/uploads/user_avatars/10820786614fe1f6d9ccbda.png)
|
Posted: 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
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
tg851
![](http://compsci.ca/v3/uploads/user_avatars/769939254ed665749ae13.jpg)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
|
|