Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello I need help getting my program to ignore upper or lowercase letter when co

ID: 3607253 • Letter: H

Question

Hello I need help getting my program to ignore upper or lowercase letter when comparing the string index. im sure im doing this completly wrong. pleasse help. Thank you

//CODE
// Created by: Monica Pierce
// Created on: 10/25/17
// Purpose:    determine whether a string is a palindrome
#include <iostream>
#include <string>
using namespace std;
int isPalindrome(string);
int main()
{
string pal;
int answer;
cout << "Please enter your palindrone." << endl;
cin >> pal;
answer = isPalindrome(pal);
  

if (answer== 1)
  cout << "You entered a palindrome." << endl;
else
  cout << "You did not enter a palindrome." << endl;
    return 0;
}
int isPalindrome(string pal)
{
  
  
  int length = pal.length();
  

  for (int x = 0; x < length / 2; x++)
  {
   if (pal[x] != pal[length - 1 - x])
   {
    if (pal[x] < pal[length - 1 - x])
    {
     pal[length - 1 - x] = static_cast<char>(x - 20);
     if
      (pal[x] != pal[length - 1 - x])
      return 0;
     else
      return 1;
    }
    else if (pal[x] > pal[length - 1 - x])
    {
     pal[x] = static_cast<char>(x - 20);
     if (pal[x] != pal[length - 1 - x])
      return 0;
     else
      return 1;
    }
   }
    else
     return 1;
  }
}

Explanation / Answer

#include <cctype>

#include <iostream>
#include <string>

using namespace std;
int isPalindrome(string);
int main()
{
string pal;
int answer;
cout << "Please enter your palindrone." << endl;
cin >> pal;
answer = isPalindrome(pal);


if (answer== 1)
cout << "You entered a palindrome." << endl;
else
cout << "You did not enter a palindrome." << endl;
    return 0;
}
int isPalindrome(string pal)
{


int length = pal.length();
char c;

for(int i=0;i<length;i++){
if(isupper(pal[i])){
pal[i] = tolower(pal[i]);
}
}

for (int x = 0; x < length / 2; x++)
{
   if (pal[x] != pal[length - 1 - x])
   {
    if (pal[x] < pal[length - 1 - x])
    {
     pal[length - 1 - x] = static_cast<char>(x - 20);
     if
      (pal[x] != pal[length - 1 - x])
      return 0;
     else
      return 1;
    }
    else if (pal[x] > pal[length - 1 - x])
    {
     pal[x] = static_cast<char>(x - 20);
     if (pal[x] != pal[length - 1 - x])
      return 0;
     else
      return 1;
    }
   }
    else
     return 1;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote