#include <iostream>
#include <cmath>
usingnamespace std;
// FUNCTION PROTOTYPE FOR read_range
void read_range(int& imin, int& imax);
// FUNCTION PROTOTYPE FOR is_prime
bool is_prime(int& k);
// DO NOT MODIFY THE MAIN ROUTINE IN ANY WAY
int main()
{
int imin(0), imax(0);
// Read in range
read_range(imin, imax);
// Print prime numbers
cout << "Primes:";
for (int k = imin; k <= imax; k++)
{
if (is_prime(k))
{
cout << " " << k;
}
}
cout << endl;
return 0;
}
// DEFINE FUNCTION read_range() HERE:
void read_range(int& imax, int& imin)
{
cout<<"Enter minimum and maximum:";
cin>>imin>>imax;
while(imin>imax)
{
cout<<"Error, Minimum must be less then maximum"<<endl;
cout<<"Enter minimum and maximum:";
cin>> imin>>imax;
}
while((imin<2 || imax<2))
{
cout<<"Error, Minimum and maximum must be at least 2"<<endl;
cout<<"Enter minimum and maximum:";
cin>> imin>>imax;
}
}
// DEFINE FUNCTION is_prime() HERE:
bool is_prime(int& k)
{
int count=0;
for(int i=2; i<=(k-1); i++)
{
if (k%i !=0)
count++;
}
if (count=(k-2))
true;
}
sorry here is the code with code tags actually working.
Here, function bool is_prime(int& k); is supposed to return a bool. But the function just terminates without returning anything.
Line 66 is wrong, it uses '=' instead of '==' so will always be true.
Some of my previous comments still apply, you don't actually need to count anything.
At lines 62-63, all that's required is to return false when (k%i) is zero, otherwise, if you reach the end of the for loop the number must be prime, so return true.
is this what you mean? because if so this isnt working either. It still only prints
Primes:
. I sent you a private message a while ago, would it be possible to continue through emails or other ways of communication for easier response ext.