我正在编写一个代码,它将(希望)允许用户输入一个数字,并将输出 2 和该数字(包括)之间的素数之和。然而,我在代码的倒数第二行遇到了一个问题。我已经查找了此问题的其他解决方案,但它们似乎不是由与我相同的错误引起的。这是代码:
#include <iostream>
using namespace std;
int Q;
int sum_primes(int N) {
cout << "Enter a number and I will generate the sums of the primes up to (and including) that number: ";
cin >> Q;
int i, count, sum = 0;
for(N = 1; N <= Q; N++) {
count = 0;
for(i = 2; i <= N/2; i++) {
if (N % i == 0) {
count++;
break;
}
}
if (count == 0 && N != 1)
sum = sum + N;
return N = sum;
}
}
int main() {
cout << "The sum of these primes is: " << sum_primes(int N);
return 0;
}