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.

#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;
	}
}
using namespace std; // It's better if you don't pollute your global namespace
string str; // Why not declare this in main()?
string stri;
int inputString (int n); // Not sure I understand why you pass an int here
bool palindromeTest (bool isPalindrome); // why do you pass this bool?
void printMessage (bool isPalindrome); // why do you pass this bool?
 
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; // <- You are "using namespace std", don't put std::
// You aren't calling any functions, so it won't do anything.
}

I suggest you read up on variable scope, the main() function, and function parameters. You would likely find your answers with great ease.

Good luck!

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.