Palindrome test program

I wrote out a palindrome test program for my c++ class. It is to include 3 functions (one to count the length of the string, one to test if it is a palindrome, and one to output whether the string is a palindrome or not using a switch statement). Visual basic isn't picking up any errors in my code, and I am able to enter the string, but I get nothing returned. If someone can please help me out and show me where I made a mistake I would appreciate it.
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
#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <string>
#include <cctype>

using namespace std;
string str;
string stri;
int inputString (int n);
bool palindromeTest (bool isPalindrome);
void printMessage (bool isPalindrome);

int _tmain(int argc, _TCHAR* argv[])
{
	int n=0;

	cout<<"THE PALINDROME TEST"<<endl;
	cout<<"Please enter a word or sentance to be tested: "<<endl;
	std::cin >> str;

}
int inputString (int n)
{
	n = str.length(); 
	if (n <= 0)
	{
		cout<<"Error: No string enters, Please Restart Program"<<endl;	
	}
return n;
}
bool palindromeTest (bool isPalindrome)
{
	isPalindrome = true;

	str = stri;
	reverse(stri.begin(), stri.end());
	if (str.compare(stri)==0)
	{
		isPalindrome = true;
		return true;
	}
	else 
	{
		isPalindrome = false;
		return false;
	}
}
void printMessage (bool isPalindrome)
{
	switch (isPalindrome)
	{
	case true:
		cout<<"The string '"<<str<<"' is a palindrome"<<endl;
	case false:
		cout<<"The string '"<<str<<"' is not a palindrome"<<endl;
	}
}
Hello sterlingf5890 :)

sterlingf5890 wrote:
Visual basic
:D

Well you need to call the function if it should do anything

ok hier it goes:
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
#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <string>
#include <cctype>

using namespace std;
bool inputString (const string &str);
bool palindromeTest (const string &str);
void printMessage (const string &str);

int _tmain(int argc, _TCHAR* argv[])
{
    string str;

    cout<<"THE PALINDROME TEST"<<endl;
    cout<<"Please enter a word or sentance to be tested: "<<endl;
    std::cin >> str;

   if(inputString(str))
       printMessage (str);
}
bool inputString (const string &str)
{
    const bool ok = (str.length() > 0);
    if (! ok)
    {
        cout<<"Error: No string enters, Please Restart Program"<<endl;    
    }
return ok;
}
bool palindromeTest (const string &str)
{
    string stri = str;
    reverse(stri.begin(), stri.end());
    return (str == stri);
}
void printMessage (const string &str)
{
    switch (palindromeTest(str))
    {
    case true:
        cout<<"The string '"<<str<<"' is a palindrome"<<endl;
    case false:
        cout<<"The string '"<<str<<"' is not a palindrome"<<endl;
    }
}
it is not tested though
Topic archived. No new replies allowed.