calling functions/ compute prime numbers

Hi everyone! I've been working on this program and I believe my functions on top are working, but in my int main I have a feeling it is wrong. I need to call getInput with no parameters and return the input, call/write isPrime to determine if the number is prime and return true if it is and false if it is not. This means dividing starting at 2 and going up to x/2. It then has to print out the list of prime numbers. If they want 2 print 1: 2 2: 3

So far I have
#include <iostream>
using namespace std;

int getInput(){
int N;
cout << "How many prime numbers do you want?";
cin >> N;
return N;
}

bool isPrime(int x){
for(int i=2; i < x / 2; i++){
if(x%i == 0){
return false;
}
}
return true;
}

int main() {
int count;
int input = getInput();
bool isPrime();
while (count <= input){
for (int i=2; i < count; i++){
if(isPrime() = true){
count++;
cout << ""<< count << ": " << i << endl;
}
}
}
}
Last edited on
In main, count is uninitialized.

Also, isPrime takes an argument (an int), but you call it with no arguments.

if(isPrime(/**/) = true) There are a couple of issues with this: = is for assignment, so you assign true to isPrime (which makes no sense, right?). == is for comparison, so if (isPrime(13) == true) is what you want. Furthermore, since isPrime returns a bool, you don't need to compare it to a boolean literal (true or false), you can simply do: if (isPrime(13))

Other than that, I strongly recommend that you use [code][/code] tags and indent your code.
Okay, thank you so much for your reply! These tips were so helpful. And yes, I did indent but pasting it in removed it all.
Okay, thank you so much for your reply! These tips were so helpful. And yes, I did indent but pasting it in removed it all.

That's why you should use code tags when posting code here.
Topic archived. No new replies allowed.