Palindrome Program Using Functions

My assignment in my class is to create a palindrome program for any given string. The main function is supposed to call an integer function named InputString that reads the characters of length n and it needs to determine if its a non-zero length. If this is so, another function named PalindromeTest is called to test if its a palindrome The returned value here is boolean. Then, from within PalindromeTest, I have to call another function, PrintMessage, upon return from PalindromeTest to display the result of the test.

I am open to any help or suggestions or criticism.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <cstring>

using namespace std;

#define false 0
#define true 1

char s[100];
char sr[100];

void InputString();
bool PalindromeTest();
void PrintMessage();

int main()
{
    InputString();
    
    system("PAUSE");
    return 0;
}

void InputString(int n=0)
{
     cout<<"Input the string you wish to be tested";
     cin.getline(s, 100);
     
     if(strlen(s)>n)
     PalindromeTest();
     
}

bool PalindromeTest()
{
     bool rvalue = true;
     
     strcpy(sr, s);
     strrev(sr);
     if(strcmp(s, sr)==0)
     {            
                  rvalue=true;
                  PrintMessage();
     }
     else
     {            rvalue=false;
                  PrintMessage();
     }
     
}


void PrintMessage(bool rvalue)
{
     if(true == rvalue)
             cout<<"The entered string IS a palindrome"<<endl;
     else
             cout<<"The entered strins IS NOT a palindrome"<<endl;
}
Please post what the problem is next time, e.g. compile error or wrong output or whatsoever...

1
2
#define false 0
#define true 1 

don't do that, true/false are already defined.

(i only mention errors my compiler gave me)
in line 12 and 14 you forgot to define the arguments you call the function with.
PrintMessage takes a bool argument, but you call it from PalindromeTest without any.
and PalindromeTest is supposed to return a bool, but it does not. (my compiler doesn't care about the missing return, i wonder why...)

change these things and the program should work.
for me it was not working with strrev, where is this function defined? so i had to write my own function, that replaced your strcpy, strrev and strcmp... thats why i said it "should" work with the changes, couldn't test it ;-)
Last edited on


PrintMessage();

finction should be .

PrintMessage(rvalue);


Hope this helps
Sorry, I will be sure to do that in the future.

I made the suggested changes, now the only error I get is a linker error with InputString().
You are getting a linker error because you've previously defined InputString without any parameters, fix it the same way you fixed your last error.
Topic archived. No new replies allowed.