I know this program has been worked on before but whenever i use this it tells me this message : error C4716: 'primeCount' : must return a value. It is the program to output the number of prime numbers in the first 50,000 numbers, in increments of 1000. So I am unsure of where i went wrong with this problem.
#include <iostream>
#include <iomanip>
#include <cmath>
constint CHILIADS = 50;
bool isPrime (int n);
int primeCount (int x, int y);
usingnamespace std;
int main()
{
cout << setw(10) << left << "Start" << setw(10) << "End" << setw(24) << "Number of Primes" << endl;
primeCount (0, 50000);
return 0;
}
// Determines whether the number is prime
bool isPrime (int n)
{
int a;
if (n == 1)
{
returnfalse;
}
for (a = 2; a <= (n / 2); a++)
{
if ((n % a) == 0)
{
returnfalse;
}
}
returntrue;
}
// Counts and organizes the prime numbers using the isPrime function
int primeCount (int x, int y)
{
bool prime;
int b;
int c = 1000;
int counter = 0;
int totalSum = 0;
for (b = x; b <= y; b++)
{
prime = isPrime (b);
if (prime == true)
{
counter++;
}
if (b == c)
{
cout << setw(10) << left << (b - 999) << setw(10) << left << b << setw(12) << counter << endl;
totalSum = totalSum + counter;
counter = 0;
c = c + 1000;
}
}
cout << endl << "Total primes in the first 50 chiliads: " << totalSum << endl;
cout << "Average number per chiliad: " << totalSum / CHILIADS << endl;
}
error C4716: 'primeCount'
If anyone could help me out with this problem that i am having it would be greatly appreciated. I hope it is a very simple fix.