aztech1977
Programmer
Hi guys, trying to use Borland C++ to create a program to read in a string value to find out if it's a palindrome. Lots of examples online but none that are too useful. My code is as below but i keep getting the errors (as seen at the bottom of the page).
On the code i have marked out which lines the errors refer to.
I'm a newbie can you help, what am i doing wrong?
//--------------------------------------------------------
int main(int argc, char* argv[])
{
AnsiString Line;
int Front;
int Back ;
bool Palindrome(char *, int, int);
//Pseudo-Code
WriteString("Enter the string to be tested");
Line = ReadStringPr("Enter the string to be tested");
Front = 1;
Back = Length(Line);
Palindrome = true; <---------------ERROR (1)
while ((Front < Back) & (Palindrome = true)); <---------------ERROR (2 & 3)
{
if (Line[Front] == Line[Back])
{
Palindrome = false; <---------------ERROR (4)
}
else
{
Front = Front + 1;
Back = Back - 1;
} //ifend
} //loopend
WriteString("Line");
if (Palindrome = true) <---------------ERROR (5)
{
WriteString("is a palindrome");
}
else
{
WriteString("is not a palindrome");
}
getchar();
return 0;
}
ERROR MESSAGES
------------------------
1. [C++ Error] SCAM1TST.cpp(25): E2277 Lvalue required
2. [C++ Error] SCAM1TST.cpp(26): E2277 Lvalue required
3. [C++ Warning] SCAM1TST.cpp(26): W8019 Code has no effect
4. [C++ Error] SCAM1TST.cpp(30): E2277 Lvalue required
5. [C++ Error] SCAM1TST.cpp(39): E2277 Lvalue required
On the code i have marked out which lines the errors refer to.
I'm a newbie can you help, what am i doing wrong?
//--------------------------------------------------------
int main(int argc, char* argv[])
{
AnsiString Line;
int Front;
int Back ;
bool Palindrome(char *, int, int);
//Pseudo-Code
WriteString("Enter the string to be tested");
Line = ReadStringPr("Enter the string to be tested");
Front = 1;
Back = Length(Line);
Palindrome = true; <---------------ERROR (1)
while ((Front < Back) & (Palindrome = true)); <---------------ERROR (2 & 3)
{
if (Line[Front] == Line[Back])
{
Palindrome = false; <---------------ERROR (4)
}
else
{
Front = Front + 1;
Back = Back - 1;
} //ifend
} //loopend
WriteString("Line");
if (Palindrome = true) <---------------ERROR (5)
{
WriteString("is a palindrome");
}
else
{
WriteString("is not a palindrome");
}
getchar();
return 0;
}
ERROR MESSAGES
------------------------
1. [C++ Error] SCAM1TST.cpp(25): E2277 Lvalue required
2. [C++ Error] SCAM1TST.cpp(26): E2277 Lvalue required
3. [C++ Warning] SCAM1TST.cpp(26): W8019 Code has no effect
4. [C++ Error] SCAM1TST.cpp(30): E2277 Lvalue required
5. [C++ Error] SCAM1TST.cpp(39): E2277 Lvalue required