B
brian.digipimp
Write a program that prompts the user to input a positive integer. It
should then output a message indicating whether the number is a prime
number. (Note: An even number is prime if it is 2. An odd integer is
prime if it is not divisible by an odd integer less than or equal to
the square root of the number.) I was given this assignment in my c++
class and I'm having trouble with it. I've looked at the professors lab
solutions but I just dont understand it. This is the code I have.
#include <iostream>
#include <cmath>
using namespace std;
int isprime(int);
int main()
{
int inputnumber;
cout << "Input a positive integer:";
cin >> inputnumber;
if (isprime(inputnumber))
cout << inputnumber << " is prime";
else
cout << inputnumber << " is not prime";
int isprime(int inval);
int retval = 1;
int counter = 2;
int inval;
while ((counter < sqrt(retval)) && retval != 0)
{
if (inval % counter == 0)
retval = 0;
counter++;
return retval;
}
return 0;
}
Im getting an ambigous call to overload on my square root function.
Other than that the program is just not working, can someone please
help me out here?
should then output a message indicating whether the number is a prime
number. (Note: An even number is prime if it is 2. An odd integer is
prime if it is not divisible by an odd integer less than or equal to
the square root of the number.) I was given this assignment in my c++
class and I'm having trouble with it. I've looked at the professors lab
solutions but I just dont understand it. This is the code I have.
#include <iostream>
#include <cmath>
using namespace std;
int isprime(int);
int main()
{
int inputnumber;
cout << "Input a positive integer:";
cin >> inputnumber;
if (isprime(inputnumber))
cout << inputnumber << " is prime";
else
cout << inputnumber << " is not prime";
int isprime(int inval);
int retval = 1;
int counter = 2;
int inval;
while ((counter < sqrt(retval)) && retval != 0)
{
if (inval % counter == 0)
retval = 0;
counter++;
return retval;
}
return 0;
}
Im getting an ambigous call to overload on my square root function.
Other than that the program is just not working, can someone please
help me out here?