/*
File: isprime.cpp
Created by: ????
Creation Date: ????
Synopsis:
This program reads in a minimum and maximum integer greater than 1
and returns all primes between the minimum and maximum.
*/
#include <iostream>
#include <cmath>
using namespace std;
// FUNCTION PROTOTYPE FOR read_range
void read_range(int& imin, int& imax);
// FUNCTION PROTOTYPE FOR is_prime
void is_prime(int& k);
// DO NOT MODIFY THE MAIN ROUTINE IN ANY WAY
int main()
{
int imin(0), imax(0);
int prime(0);
cout<<"Enter minimum and maximum:";
cin>>imin,imax;
// 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)
{
while(imin>imax)
{
cout<<"Error, Minimum must be less then maximum"<<endl;
cout<<"Enter minimum and maximum:";
while((imin<2 || imax<2))
{
cout<<"Error, Minimum and maximum must be at least 2"<<endl;
cout<<"Enter minimum and maximum:";
}
}
}
Hello, So i have been working on this code for literally hours and im down to only one error when trying to compile. The exact error is isprime.cpp:39: error: "could not convert `is_prime(((int&)(& k)))' to `bool'".
I understand what the program is supposed to do, it reads in two numbers that the user inputs, first being min and next max. From there i have a void function to ensure two conditions are met, next i have a is_prime function that determines all the numbers that are prime between the min and max number. I believe i have everything correct but i am just lost at what that error means. I am very basic at c++ and this is for one of my home work assignments, i dont need a handout but i am officially begging for help. Thank you so much for looking at this post and thank you even more if you respond.
The problem is i need to make is_prime a void function for this assignement and is_prime(k) is the template the instructor is having us use for this program. I changed the is_prime void function to
{
if(k%(k-1)!=0)
true;
else
false;
}
im so lost with how you two are putting your answers , im really bad at C++. So you can you simplify what your trying to say.
in my head, the way this function is working is its taking the first number pushing into the if function (is_prime(k)) then jumps to the void function which states that if (k%(k-1)!=0) then its true..... other wise false. It then jumps back up and prints out k as prime. Rinse repeat.
The biggest problem is i cant get Is_prime to actually return true or false which i thought would work with the above code
your answer fixed my problem gulshan singh, until you said "bool is_prime()" i have not seen that before. I combed through the chapter on functions in my book and my lecturer never said that either so i guess its just a lack of knowledge. Thanks for the help.