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 60 61 62 63 64 65 66 67 68 69
|
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
bool isAPalindrome(char *inString, const char* start, const char* end);
int main()
{
const int SIZE = 256;
char inString[SIZE]{};
int first, second;
while (1) {
cout << "Enter a string: ";
cin.getline(inString, SIZE);
cout << inString;
if (isAPalindrome(inString, &inString[0], &inString[strlen(inString) - 1])) {
cout << " is a palindrome" << endl;
}
else cout << " is not a palindrome." << endl;
cout << "Pick 2 elements, everthing in between "
<< "and including the elements wil be checked for palindrome." << endl;
cout << "1st element: ";
cin >> first;
cout << "2nd element: ";
cin >> second;
if (isAPalindrome(inString, &inString[first], &inString[second])) {
for (first; first <= second; first++) {
cout << inString[first];
}
cout << " is a palindrome" << endl;
}
else {
for (first; first <= second; first++) {
cout << inString[first];
}
cout << " is not a palindrome." << endl;
}
cin.ignore();
}
system("pause");
return 0;
}
bool isAPalindrome(char *inString, const char* start, const char* end)
{
if (start < end) {
if (*start != *end)
return false;
toupper(*inString); // Green squiggly line here
isAPalindrome(inString, start+1, end-1);
}
return true;
}
|