
-----------------------------------
cycro1234
Thu Nov 25, 2004 9:29 pm

if statements help
-----------------------------------
Aight, so i'm learning this new thing in turing called "error trapping". Annoying lil bugger if u ask me, but important nonetheless. Neways, lets say I have an if statement for one value. And i want the program to end when the value is something other than the one i want. That is, ANY value, meaning string or real number. Example:

get x

if x = 5 then
put ""

now i need the code to make the program output the next part IF x is any value other than 5, including strings.

put "You will read this if you inputted any other value for x other than 5" put "including a string" 

else would work, but only if the input is a real type. I need to cover ALL possiblities. Thx in advance

-----------------------------------
Hikaru79
Thu Nov 25, 2004 9:51 pm


-----------------------------------
Your question is kinda convoluted and hard to understand. But I'll post an example error trapping statement and you can probably adapt it to your own use. Say you want the user to input an INTEGER. This is what you do:


var userInput : string
loop
    put "Please enter an integer:  " ..
    get userInput
    if strintok (userInput) then
        put "Congratulations! You know what an integer is!"
    else
        put "You suck. That's not an int!"
    end if
end loop


-----------------------------------
cycro1234
Thu Nov 25, 2004 10:00 pm


-----------------------------------
ok but what if i dont want to do it for an integer? What if i want to do it for a string?

-----------------------------------
cycro1234
Thu Nov 25, 2004 10:03 pm


-----------------------------------
Nvm, i think i got it. THX A LOT!

-----------------------------------
cycro1234
Thu Nov 25, 2004 10:16 pm


-----------------------------------
UGH! I didn't get it. I want the user to input a real number. If the user inputs a letter instead of a number, i want the program to tell the user to input again properly.

-----------------------------------
Cervantes
Fri Nov 26, 2004 4:25 pm


-----------------------------------
I'm not that good with string manipulation but here's my approach:

var userInput : string

loop
    locate (1, 1)
    put "Enter a real number : " ..
    get userInput
    exit when index ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghigjklmnopqrstuvwxyz,/?;':\"[]{}`~!@#$^&*()_+|-", userInput) = 0
    locate (1, 1)
    put repeat (" ", maxcol)
end loop
var realNum := userInput
put "You entered ", realNum, "."


-----------------------------------
beard0
Fri Nov 26, 2004 7:26 pm


-----------------------------------
var input : string
var num : real
loop
    put "Enter a real number: " ..
    get input
    cls
    exit when strrealok (input)
    put "That was not a real number!"
end loop
num := strreal (input)
put "The number entered is ", num

-----------------------------------
Cervantes
Sat Nov 27, 2004 10:27 am


-----------------------------------
:o ah hell :?  I didn't think there was a strrealok command.  I must have typed strealok when I first tried it.   
Given that there is a strrealok command, use beard0's code 8)

-----------------------------------
con.focus
Sun Nov 28, 2004 7:32 pm


-----------------------------------
uh oh

-----------------------------------
con.focus
Sun Nov 28, 2004 7:34 pm


-----------------------------------
shoot  sry  if  u want it to end when it encounters  sumthing else then  use a loop and tell use the exit when command  to tell it when to stop the loop

-----------------------------------
beard0
Sun Nov 28, 2004 10:18 pm


-----------------------------------
con.focus:  what does that code have to do with asking for numerical input, and allowing user stupidity (ie, they enter a non-number)?
