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;
}
}