So I'm writing this code that check if a five-digit number is a palindrom or not. But I get the error message 'Code will never be executed' on line 28. Please tell me what I'm doing wrong
If a write a 5-digit number the program starts over again. But I want it to continue. If a write a 3-digit number for example the program says, Not enough numbers and then starts over. if a write a 6-digit number the program says, To many numbers and then starts over.
#include <iostream>
#include <string>
int main()
{
unsigned number = 0;
while (true)
{
std::cout << "Enter a five digit number: ";
std::cin >> number;
if (number > 9999 && number < 100000)
{
break;
}
std::cout << "Not the correct number of digits!\n\n";
}
std::cout << "\n";
// create a string from the number
std::string num_str = std::to_string(number);
if ((num_str[0] == num_str[4]) && (num_str[1] == num_str[3]))
{
std::cout << "The five-digit number is a palindrome!\n";
}
else
{
std::cout << "The five-digit number is NOT a palindrome!\n";
}
}
Enter a five digit number: 1234
Not the correct number of digits!
Enter a five digit number: 1223456
Not the correct number of digits!
Enter a five digit number: 12345
The five-digit number is NOT a palindrome!
Enter a five digit number: 22522
The five-digit number is a palindrome!