Alright, so I'm supposed to write a program that spits out all the prime numbers before 10,000, and I have to use a separate function for the math. I created a program that does just that, but I'm not supposed to cout x in the prime function. My professor told me that I'm supposed to return 1 (in the prime function) if x is prime then spit it out (in the main function), or return 0 if x is not prime. I'm not sure how to create an if statement asking if the return value for the prime function is 1 or 0.
Any help is very appreciated.
By the way, the code below is the last working code I created.
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
usingnamespace std;
int prime(int x, int y) {
for (x=2; x<10000; x++) {
bool prime = true;
for (y =2; y*y<=x; y++) {
if (x % y == 0) {
prime = false;
break;
}
}
if (prime) {
cout << x << " ";
}
}
return x;
}
int main(int argc, char *argv[]) {
int x,y;
prime(x,y);
return 0;
}