Prime help

This program works but needs to be reworked so that the main function is the one that initiates the program-rather the int getNumberFromUser and isPrime doing all the work. How would I go about doing this? Thanks!

//The program should have two functions:
//int getNumberFromUser(); -> asks user for input and ensures the number is >2
//bool isPrime(int n); -> returns true if n is prime else false.

#include <iostream>
using namespace std;

int getNumberFromUser();
bool isPrime(int);



int main()
{
int n = getNumberFromUser();
isPrime(in);
return 0;
}


int getNumberFromUser()
{
int num;
cout << "Please enter a positive integer\n";
cin >> num;
if (num>=2)
return num;
else
cout<<"Please enter a number greater than or equal to 2";
}

bool isPrime(int n)
{
int num, prime;
for(int i=2; i<=num; i++)
{
prime=true;
for(int n=2; n<=(i-1); n++)
{
if(i%n==0)
{
prime = false;
}
}
if(prime)
{
cout << i << " is prime\n";
}
}
return prime;
}
the main function is the one that initiates the program

main() is always the first function being called when your program starts, whether you want it or not.
Is this something your teacher asked you to do? Either you or your teacher is confused here.

Is your teacher asking you not to use functions?

Please elaborate!
Topic archived. No new replies allowed.