Question: the question was to write a program that prompts the user to enter a five-digit integer and determines whether it is a palindrome number. A

the question was to write a program that prompts the user to enter a five-digit integer and determines whether it is a palindrome number. A number is palindrome if it reads the same from right to left and from left to right.

#include using namespace std; int main() { // extract the ones digit from any given number int number, onesdigit, tensdigit, hundredsdigit, thousandsdigit, tenthousandsdigit; cout << " please anter a number "; cin >> number; onesdigit = number % 10; tensdigit = (number / 10) % 10; hundredsdigit = (number / 100) % 10; thousandsdigit = (number / 1000) % 10; tenthousandsdigit = (number / 10000) % 10;

cout << " the ones digit is " << onesdigit << endl;

// extract the tens digit from any given number cout << " the tens digit is " << tensdigit << endl;

// extract the hundreds digit from any given number cout << " the hundreds digit is " << hundredsdigit << endl;

// extract the thousandsd digit from any given number cout << " the thousands digit is " << thousandsdigit << endl;

// extract the tenthousands digit from any given number cout << " the ten thousands digit is " << tenthousandsdigit << endl;

// to find out if a 5 digit number is a palindrome if (onesdigit == tensdigit == hundredsdigit == thousandsdigit == tenthousandsdigit) { cout << " you do have a palindrome " << endl;

} else { cout << " you do not have a palindrome " << endl; }

}

Whenever I run this program and I have a palindrome number the program is displaying I do not have a palindrome and vice versa. What did I do wrong? Why is it swapped? I am using c++ on visual studio.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!