Hello Everyone: I'm currently working on a code that checks if a string is a palindrome using recursion. I've been trying to fix it for a few hours now and I have gotten less errors, thank god. But I'm stuck on the part of my code where the error is:
ERROR!
g++ /tmp/w8b7ylecAL.cpp
/tmp/w8b7ylecAL.cpp:4:20: error: expected ')' before '(' token
4 | struct palin(string (text, int left, int right)){
| ~ ^~
| )
/tmp/w8b7ylecAL.cpp: In function 'int main()':
/tmp/w8b7ylecAL.cpp:48:47: error: expected primary-expression before '<<' token
48 | cout << "this is a palindrome: " << palin << endl;
| ^~
/tmp/w8b7ylecAL.cpp:50:51: error: expected primary-expression before '<<' token
50 | cout << "this is not a palindrome: " << palin << endl;
| ^~
I think maybe it has to do with "palin" which is a structure above my main function. Can I pass a struct a function in my main or is it a syntax issue maybe?
Here is my code for context:
#include <iostream>
using namespace std;
struct palin(string (text, int left, int right)){
int text = string;
int input1(stirng input1)
{
if (input1 != text.length()/2)
{
return false;
}
else{
return true;
}
}
int input2(string input2)
{
if (input2 != text.length()/2)
{
return false;
}
else{
return true;
}
}
int input3(string input3)
{
if (input3 != text.length()/2)
{
return false;
}
else{
return true;
}
}
};
int main(){
//declaring the variables input1, input2, input3
string input1 = "Kayak"; //will return true
string input2 = "Mr. Owl ate my metal worm"; //will return true
string input3 = "Hello";//return false
cout << "true " << palin << endl;
cout << "false " << palin << endl;
}
I expected my code to return true if it was a palindrome and false if not. I know true and false is usually used in bool, However I have not learned bool yet so I do not know how to apply it in my code, especially since I'm very much new to c++