So i am working with code that has to do several things. It must add all of the digits of a randomly generated integer, reverse those digits, and also determine if the integer is a palindrome and if it is a prime number. I have this and I am getting a few errors and can not figure out exactly what I am doing wrong (except the part to determine if the integer is prime i don't think I did that correctly).
#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, int reverse)
{
if (reverse(number));
return (number = (reverse) % 10);
elseif (isPalindrome(number/10, reverse))
returnfalse;
reverse /= 10;
return (number % 10 == (reverse) % 10);
}
bool isPrime(int number);
{
if(number%2!=0)
returntrueelsereturnfalse
}
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(31);
//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;
}
return 0;
}
I don't post here unless i've exhausted my efforts elsewhere. I have found solutions to my errors and explanations but none of them work for me or they are not relevant to my code. I wouldn't learn anything if i simply posted here without trying myself at first. Its in the beginner section because i am a beginner. Things that might be obvious fixes to you are not for me. Only been in a college coding class for a month.
Making mistakes is ok and part of the learning process. In order to get help you need to provide information so that people know what to look for. Just dumping a load of code doesn't work.
First step I recommend is to compile your code and paste all the error messages in original.