This is what I have so far and I can\'t get this to work. please help. The quest
ID: 3622102 • Letter: T
Question
This is what I have so far and I can't get this to work. please help.The question is , Write a program that uses the function isNumPalindrome. Test the program with these numbers. 10,34,22,333,678,67876,44444 , and 123454321. Thanks
#include <iostream>
#include <cmath>
using namespace std;
bool isNumPalindrome (int num);
int main()
{
int pwr = 0;
int num = 0;
cout << "Enter a number to see if it is a palindrome: " << endl;
cin >> num;
if (num < 10)
return true;
else
{ while (num /static_cast<int> (pow(10.0,pwr))>=10)
pwr++;
while(num >= 10)
{
int tenTopwr = static_cast<int>(pow(10.0,pwr));
if ((num / tenTopwr)!= (num % 10))
return false;
else
{
num = num % tenTopwr;
num = num / 10;
pwr = pwr - 2;
}
}
return true;
}
}
Explanation / Answer
please rate - thanks
you basically had it
#include <iostream>
#include <cmath>
using namespace std;
bool isNumPalindrome (int num);
int main()
{
int num = 0;
cout << "Enter a number to see if it is a palindrome: " << endl;
cin >> num;
if(isNumPalindrome(num))
cout<<num <<" is a palindrome ";
else
cout<<num <<" is not a palindrome ";
system("pause");
return 0;
}
bool isNumPalindrome (int num)
{int pwr = 0;
if (num < 10)
return true;
else
{ while (num /static_cast<int> (pow(10.0,pwr))>=10)
pwr++;
while(num >= 10)
{
int tenTopwr = static_cast<int>(pow(10.0,pwr));
if ((num / tenTopwr)!= (num % 10))
return false;
else
{
num = num % tenTopwr;
num = num / 10;
pwr = pwr - 2;
}
}
return true;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.