Question: Program isprime.cpp: a. Write a function read_range() which reads in the minimum and maximum values. The function has two parameters listed in the following order:
Program isprime.cpp: a. Write a function read_range() which reads in the minimum and maximum values. The function has two parameters listed in the following order: i. the minimum value of the range; ii. the maximum value of the range. Both parameters should have integer type. Both parameters should be passed by reference. The function does not return any value, but it modifies the two parameters. The function prompts for the minimum and maximum values. If the minimum or maximum values are less than 2, then the program prints an error message and prompts again for the two values. If the minimum value is greater than the maximum value, then the program prints an error message and prompts again for the two values. The program prints error messages and prompts for the minimum and maximum values until it gets two values greater than or equal to 2 and such that the minimum is less than or equal to the maximum. b. Write a function is_prime() which determines if a number is prime. The function has one integer parameter. The function returns true if the input parameter is prime and false otherwise. A number a is prime if and only if (a mod b 0) for b = 2, 3, ..., (a - 1).
Do not modify anything in the main function in the template (below).
TEMPLATE:
#include
using namespace std;
// FUNCTION PROTOTYPE FOR read_range
// FUNCTION PROTOTYPE FOR is_prime
// 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 j = imin; j <= imax; j++) { if (is_prime(j)) { cout << " " << j; } } cout << endl;
return 0; }
// DEFINE FUNCTION read_range() HERE:
// DEFINE FUNCTION is_prime() HERE:
****** is_prime() should be boolean, and for example if 2 and 9 were inputted, the output would be 2,3,5,7.
I can't figure out how to output the 2, and not output the 9.
Thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
