This program runs but no matter what I enter it outputs \"Try AgainTry AgainPrim
ID: 3660135 • Letter: T
Question
This program runs but no matter what I enter it outputs "Try AgainTry AgainPrimes:" Then stops working. The instructions are below the code. The program should read two numbers, find all the primes between them, and print errors ifthe minimum or
#include <cmath>
using namespace std;
// FUNCTION PROTOTYPE FOR read_range
void read_range(int &min_val, int &max_val);
// FUNCTION PROTOTYPE FOR is_prime
double is_prime(int a);
// 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 &min_val, int &max_val){
cout << "Enter the values: ";
cin >> min_val >> max_val;
if (min_val || max_val < 2){
cout << "Try again";
if (min_val > max_val);{
cout << "Try again";}}
else (min_val < max_val);}
// DEFINE FUNCTION is_prime() HERE:
double is_prime(int a){
for (int b = 0; b <= a; b++){
if ( a % b == 0){
cout << "True";}
else{
cout << "False";}}}
Explanation / Answer
#include #include using namespace std; // FUNCTION PROTOTYPE FOR read_range void read_range(int &min_val, int &max_val); // FUNCTION PROTOTYPE FOR is_prime double is_prime(int a); // 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 coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.