Hi,
I have to find the divisors of all numbers less than a number inputed by the user and state if a number is prime if no divisors. I have this code so far, but I'm getting the wrong output and not sure how to list all the numbers less than the input number. Please help.
#include <iostream>
using namespace std;
// function declarations
// -------------------
bool isPrime (int);
// main function
// -------------------
int main ()
{
int userNum, divisor;
bool prime;
cout << "Please enter an integer between 10 and 100:";
cin >> userNum;
if(userNum < 10 || userNum > 100)
{
cout << "Please enter an integer between 10 and 100:";
}
else
for (int counter = 2; userNum > counter; counter ++)
{
if (userNum % counter == 0)
{
cout << userNum << "'s divisors are:" << counter;
}
}
isPrime(userNum);
prime = isPrime(userNum);
if (prime == 1)
{
cout << userNum << " is a prime number" << endl;
}
return 0;
}
// function definitions
// -------------------
bool isPrime(int userNum)
{
for(int counter = 2; counter < userNum; counter++)
{
if(userNum % counter ==0)
return false;
}
return true;
}