help with palindrome question
Author |
Message |
JR
|
Posted: Mon Apr 19, 2004 4:12 pm Post subject: help with palindrome question |
|
|
code: |
function palindrome (s : string) : boolean
if s (1) = s (*) then
palindrome (s (2 .. * -1))
end if
end palindrome
var s : string
put "Enter a word"
get s
if palindrome (s) = true then
put s, "is a palindrome"
else
put s, "is not a palindrome"
end if
|
this is the code, i need to make the program find the palindrome using recustion. I need help fixin the prog, some strange errors. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
AsianSensation
|
Posted: Mon Apr 19, 2004 4:18 pm Post subject: (No subject) |
|
|
well, right now you are calling a function like a procedure, you can't do that.
Another error, is that when you are passing the string as a parameter, if the string you pass is 1 character long, passing s (2 .. * - 1) will give you error.
that's about it, from what I see |
|
|
|
|
 |
EDEN-E
|
Posted: Mon Apr 19, 2004 4:41 pm Post subject: (No subject) |
|
|
code: | function palindrome (s : string, i : int) : boolean
if length(s) = i then result true end if
if s(i) = s(length(s)-i+1) then
if palindrome (s, i + 1) then
result true
end if
end if
result false
end palindrome
var s : string
put "Enter a word"
get s
if palindrome (s, 1) = true then
put s, " is a palindrome"
else
put s, " is not a palindrome"
end if |
hmm... when you use function, you have to return the result. |
|
|
|
|
 |
Tony

|
|
|
|
 |
|
|