I agree with shadowCODE. It looks to me like the code is working correctly. In his example he asked for 7 prime numbers and it printed out 7 prime numbers. If this is wrong then please explain what output you expect when the input is 7.
#include <iostream>
usingnamespace std;
int getInput() {
int input;
cout << "How many prime numbers do you want? ";
cin >> input;
return input;
}
bool isPrime(int x) {
for (int i = 2; i <= x/2; i++) {
if (x % i == 0) {
returnfalse;
}
}
returntrue;
}
int main() {
int N = getInput();
int count = 1;
int num = 2;
if(N<=0)
{
N=N*-1;
while (count <= N) {
if (isPrime(num)) {
cout << count << ": -" << num << endl;
count++;}num++;}
}else{
while (count <= N) {
if (isPrime(num)) {
cout << count << ": " << num << endl;
count++;}num++;}}
return 0;}