Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

who identifies stakeholders for a project in project management

Answered: 1 week ago