In: Computer Science
This is C++, please insert screenshot of output please.
Part1: Palindrome detector
Write a program that will test if some string is a palindrome
#include <iostream>
using namespace std;
bool palindromeWhile(string s, int size)
{
bool status = false;
int i = 0 , j = size - 1;
while( i <= j)
{
if(s[i] == s[j])
{
status = true;
}
else
{
return false;
}
j--;
++i;
}
return status;
}
int main()
{
const int SIZE = 100;
string inputString;
char str[SIZE], again;
int size;
do
{
cout<<"Enter a string: ";
getline(cin,inputString);
if (palindromeWhile(inputString, inputString.size()))
cout << inputString << " is a palindrome.\n";
else
cout << inputString << " is not a palindrome.\n";
cout << "Try another string? (Y/N) ";
cin >> again;
cin.ignore();
} while (again == 'Y' || again == 'y');
system("pause");
}
==================================================================
SEE OUTPUT
========================================
Thanks, let me now if there is any concern.