Computer Science Canada

Another help in recognition!

Author:  DBZ [ Thu Dec 25, 2003 7:34 pm ]
Post subject:  Another help in recognition!

Hey guys, i need this program to be able to recognize wether the user input is a number, a letter, or a sign. For example, if i enter "55te+-", the program should output, 55 is a number, te is a letter, +- is a symbol.
Please try ur suggestion in the program and repost the program here!
Here is the program:

var word,t:string

const numbers:="0123456789"
const symbols:="`~!@#$%^&*/*-+"
put"enter a word: "..
get word
for i:1.. length(word)
var v:=word(i)
put v
if v= numbers then

put" is a number"
elsif v=symbols then

put v, " is a symbol"
end if
end for

Author:  Thuged_Out_G [ Thu Dec 25, 2003 9:03 pm ]
Post subject: 

code:

var word:string

put "Enter word: "..
get word

if word="a" or word="b" or word="c" or word="d" or word="e" or word="f" or word="g" or word="h" or word="i" or word="j" or word="k" or word="l" or word="m" or word="n" or word="o" or word="p" or word="q" or word="r" or word="s" or word="t" or word="u" or word="v" or word="x" or word="y" or word="z" then

put "Your input(",word,")is a letter"

elsif word=1 or word=2 or word= 3 or word= 4 or word= 5 or word= 6 or word= 7 or word= 8 or word= 9 or word= 0 then
put "Your input(",word,")is a number"

elsif word="!" or word="`" or word="~" or word="!" or word="@" or word="#" or word="$" or word="%" or word="^" or word="&" or word="*" or word="(" or word=")" or word="/" or word="+" or word="-" then
put "Your input(",word,")is a symbol"
else
put "this is the most unefficient program i could write for you :)"
end if

Author:  AsianSensation [ Thu Dec 25, 2003 10:54 pm ]
Post subject: 

you have the right idea, but learn to use the index function. index each individual substring in the const values you declared. If the position returned is not 0, then you found it, and you can output accordingly.
code:

const numbers := "0123456789"

for i : 1 .. length (word)
    if index (numbers, word (i)) not= 0 then
        put word (i), " is a number"


same thing for letters and symbols.

Author:  DBZ [ Fri Dec 26, 2003 7:02 pm ]
Post subject: 

Hye thanx a lot guyz! I really apreciate ur help!


: