Write a menu-driven program that allows users do two options:
Option 1: It can tell whether a word, phrase, or sentence entered at the keyboard is a palindrome,
which is spelled the same in backward as well as in forward.
All punctuation characters should not be counted in the calculation for the palindrome.
Option 2: It compares two positive integers entered at the keyboard and returns the number of
decimal places (i.e. the ones, tens, hundreds place, and so on) that have the same digit.
Validate your input values: do not accept character(s) and negative and/ or floating-point values.
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main(void){
char word[81];
do{
bool palindrome=true;
int ShowMainMenu();
{
int choice;
cout << "1: Palindeome\n";
cout << "2: Compare Two Integers\n";
cout << "3: End program\n";
while ( !(cin >> choice) || choice <= 0 || choice > 3)
{
cout << "Error invalid choice try again.\n";
}
return choice;
}
cout << "Please enter a word" << endl;
cin>>word;
int length = strlen(word);
for (int i=0; i<length; i++){
word[i] = toupper(word[i]);
}
int(length/2);
if (length>0){
for(int i=0;i<(length);i++)
{
if(word[i]!=word[length-1-i])
palindrome=false;
}
}
if(palindrome==true)
{
cout << "The word is a palindrome" << endl;
}
else
{
cout << "The word is not a palindrome" << endl;
}
} while (0 != strcmp(word, "END"));
return(0) ;
}
int main()
{
string num1, num2;
int size, decimalCounter = 0;
bool decimalFound1 = false, decimalFound2 = false, goodInput = false; //These are to indicate whether we found a decimal place in the number
cout << "Please enter the first number: ";
cin >> num1;
cout << "Please enter the second number: ";
cin >> num2;
//Find the smallest size number
if(num1.size() > num2.size())
size = num2.size();
else
size = num1.size();
//If the input was verified to be good, check and see if they are the same, if so, increment the decimal counter
if(goodInput == true && num1[i] == num2[i])
++decimalCounter;
//reset the good input variable
goodInput = false;
}
cout << "\n\nThere were exactly " << decimalCounter << " similar digits in your two numbers.";
//Pause the program
cin.sync();
cin.get();
return 0;
}