i am trying to create a program that allows me to see if a sentence is a palindrome. this is what i have but something is wrong.

CLS
DIM a$(1 TO 5)
FOR i = 1 TO 5
INPUT "give me word"; word$
NEXT i

LET differflag = 0
FOR i = 1 TO 5
IF a$(i) <> a$(5 - i) THEN
LET differflag = 1
END IF
NEXT i
IF differflag = 1 THEN
PRINT " not a palindrome"
ELSE PRINT "palindrome"
END IF

i am trying to create a program that allows me to see if a sentence is a palindrome. this is what i have but something is wrong.

CLS
DIM a$(1 TO 5)
FOR i = 1 TO 5
INPUT "give me word"; word$
NEXT i

LET differflag = 0
FOR i = 1 TO 5
IF a$(i) <> a$(5 - i) THEN
LET differflag = 1
END IF
NEXT i
IF differflag = 1 THEN
PRINT " not a palindrome"
ELSE PRINT "palindrome"
END IF

Solution:
Your problem was that you used 2 different variables subscripted and scalar.
CLS
DIM a$(1 TO 5)
FOR i = 1 TO 5
INPUT "give me word";a$(i)
NEXT i

LET differflag = 0
FOR i = 1 TO 5
IF a$(i) <> a$(5 - i) THEN
LET differflag = 1
END IF
NEXT i
IF differflag = 1 THEN
PRINT " not a palindrome"
ELSE
PRINT "palindrome"
END IF

contact me for more info ba13231@yahoo.com

// Program for checking Palindrome
// If already Palindrome it will show accordingly
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main( int argc ,char *argv[] )
{
unsigned char str[100];
unsigned char temp[100];
int i = 0,j = 0,k = 0,size=0;
int valid = 1;
int flag = 0;
if( argc > 1 )
{
str[0] = '\0';

for(i=1;i<=( argc - 1 );i++)
{
strcat(str,argv);
if( i <= ( argc - 2 ) )
strcat(str," ");
}

i=0;
while( str != '\0' )
{
if( i == 100 )
{
valid = 0;
printf("string length is not correct");
break;
}
else
{
if( ( str < 65 || str > 90 ) && ( str < 97 || str > 122 ) )
{
valid = 0;
printf("invalid data string");
break;
}
i++;
}
}
if( valid == 1 )
{
i=0;
while( str != '\0' )
i++;
size = i-1;

for( j=0;j<size ;j++)
{
if( j == 0 )
str[j] = toupper(str[j]);
else if(str[j] == ' ' )
{
flag = 1;
}
else
{
if( flag == 1 )
{
str[j] = toupper(str[j]);
flag = 0;
}
}
}

flag = 0;
for( k=0,j=i-1 ; j >=-1 ; j--,k++)
{
if( k == 0 )
temp[k] = toupper(str[j]);
else if( str[j] == ' ' )
{
temp[k-1] = tolower(temp[k-1]);
temp[k] = str[j];
flag = 1;
}
else if( j == -1 )
{
temp[k-1] = tolower(temp[k-1]);
flag = 1;k--;
}
else
{
if(flag == 1)
{
temp[k] = toupper(str[j]);
flag = 0;
}
else
temp[k] = str[j];
}
}
temp[k] = '\0';
if( stricmp(str,temp) == 0 )
printf("string is a palindrome");
else
printf("%s" " %s",str,temp);
}
}
else
printf("improper arguments");
return 0;
}

(defun palindrome ()
  (format t "Please enter your word or phrase: ")
  (force-output)
  (let ((word (read-line)))
    (format t "Your word '~a' ~:[is not~;is~] a palindrome"
      word
      (string-equal word (reverse word)))))

Strings in BASIC are not treated as arrays. Only C-based languages and Pascal do that.

A string array is an array of strings in basic, not an array of characters.

You need the SUBSTR(string, first, length) to look at a portion of a string.

Here is an example using a modern language like Python ...

def is_palindrome(phrase):
    """
    take a phrase, convert to all lowercase letters, create a
    list of the characters (ignore punctuation marks and whitespaces)
    if it matches the reverse order, then it is a palindrome
    """
    phrase_letters = [c for c in phrase.lower() if c.isalpha()]
    return (phrase_letters == phrase_letters[::-1])
 
# test it ...
phrase = "Madam in Eden I'm Adam"
if is_palindrome(phrase):
    print '"%s" is a palindrome' % phrase
else:
    print '"%s" is not a palindrome' % phrase
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.