I'm stuck on trying to implement a function code for the palindrome number prototype I entered. I just don't know where to look. Something I've never done. Can someone give a hint or example? is it like an if statement. like say is it something like:
if(reverse = sumDigits){
return = true
}
else {
return = false}
The following is what I have to work with. All i have to really do is prototypes which is done and implement the function statements. Thank you for any assistance.
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
usingnamespace std;
constint NUM_VALS = 10; //the maximum number of values to use
/********* Put the function prototypes below this line *********/
void sumDigits(int number){
if(number < 10) cout << number;
else{
cout << number%10 + (number / 10);
}
}
void reverse(int number){
if(number < 10) cout << number;
else{
cout << number%10;
reverse(number / 10);
}
}
bool isPalindrome(int number);
bool isPrime(int number);
int main()
{
int number, //holds the random number that is manipulated and tested
loopCnt; //controls the loop
//set the seed value for the random number generator
//Note: a value of 1 will generate the same sequence of "random" numbers every
// time the program is executed
srand(1);
//Generate 10 random numbers to be manipulated and tested
for( loopCnt = 1; loopCnt <= NUM_VALS; loopCnt++ )
{
//Get a random number
number = rand();
//Display the sum of adding up the digits in the random number, the reversed
//random number, and whether or not the number is palindromic or a prime number
cout << "The number is " << number << endl
<< "----------------------------------------" << endl
<< "Adding the digits result" << setw(16) << sumDigits( number ) << endl
<< "Reversing the digits result" << setw(13) << reverse(number) << endl
<< "Is the number a palindrome?" << setw(13) << (isPalindrome(number)? "Yes" : "No") << endl
<< "Is the number prime?" << setw(20) << (isPrime(number)? "Yes" : "No") << endl
<< endl << endl;
}
/** If the extra credit is being attempted, call the extra function below this line **/
return 0;
}
/********* Code the functions below this line *********/
The following is what I came up with for the palindrome code where I have to call the reverse number. looking for the second set of eyes can someone correct me with what is wrong? Thank you for your input.
bool isPalindrome( int num, int reverse) // A recursive function to find out whether num is palindrome
// Base case (needed for recursion termination)
{
if (reverse(num))
return (num = (reverse) % 10);
else if (isPalindrome(num/10, reverse))
return false;