I\'m having a problem adding some stuff to my program. It runs and compiles just
ID: 3536247 • Letter: I
Question
I'm having a problem adding some stuff to my program. It runs and compiles just fine. It's just when i have an uppercase word to the palindrome checker like " Mom" it would display that it is not a palindrome while, "mom" correctly identifies as a palindrome. How can I make it so it can recognize uppercase and special characters? Explanation and code would be appreciated. ALSO, how can I add it to where I can have two words? like "Hello There" to display in reverse or check if it's a palindrome. There might be some A A A A 's in the lines of code, idk why, I copied straight from my editor to here. Sorry.
1 //*********************************************************************************
2 //Program Filename: Recursion
5 //Description: This program takes a string as an input, and determines
6 // if this it is a palindrome.
7 //Input: The user will input a choice whether he/she wants to reverse a word,
8 // determine if it's a palindrome or quit.
9 //Output: The program will display the reversed word or determine if it is a
10 // palindrome.
11 //*********************************************************************************
12
13 #include <iostream>
14 #include <cmath>
15 #include <cstring>
16 #include <string>
17
18 using namespace std;
19 using std::endl;
20 using std::cout;
21 using std::cin;
22
23 bool palindrome( int first, int last, char inputString[]);
24 void reverse( string , int);
25
26 int main()
27 {
28 int choice;
29 int first = 0;
30 int last = 0;
31 char inputString[100];
32 bool running = true;
33
34 do {
35 cout << " " << endl;
36 cout << "Do you want to reverse a string, check if it's a palindrome, or quit? " << endl;
37 cout << "(Press 1 for reverse, 2 for palindrome, and anything else to quit) " << end l;
38 cin >> choice;
39
40 switch ( choice)
41 {
42 case 1: (choice == 1); {
43 string inputString;
44
45 cout << " Please enter a word: ";
46 cin.ignore();
47 getline(cin, inputString);
48 cout << "string reversed: ";
49 reverse(inputString, inputString.size());
50 break;
51 }
52
53 case 2: (choice == 2); {
54
55 cout << " Please enter a word: ";
56
57 cin >> inputString;
58 last = strlen(inputString);
59
60 if (palindrome( first, last - 1, inputString) == true)
61 cout << "You have entered a palindrome!";
62
63 else
64 cout << "This is not a palindrome.";
65 cout << " " << endl;
66
67 break;
68 }
69
70 default: {
71 cout << "Thank you and peace out!" << endl;
72 running = false;
73 break;
74 }
75 }
76
77 }while(running);
78
79 //reverse string part.
80 //
81
82 return 0;
83 }
84
85 bool palindrome( int first, int last, char *inputString){
86
87 //if the next first index is greater than the next last index program concludes that all the elements in array have been compared and therefore input should be a palin drome retuned as true.
88
89 if (first > last)
90 return true;
Explanation / Answer
bool palindrome( int first, int last, char *inputString)
{
if (first > last)
return true;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.