I have 3 instructions-
1- Use rand() to generate a number less then 100 and greater than 1
2- Call the prime() function to test the result
3- Print out the result
So far i have found how to get a prime number but don't know how to fill up the conditions.(how to use rand() function)
#include <iostream>
using namespace std;
int smallFactor(int x) {
int answer = 2;
while (x % answer != 0) answer++;
return answer;
}
int main() {
int n;
cout << "Enter a number greater than 1: " << endl;
cin >> n;
if (n<1 ||n>99) cout<<"Illegal";
else if (n == smallFactor(n)) cout << "That is prime.";
else cout << "That is not prime.";
cout << endl;
return 0;
}