I am practicing some book problems, and I am not able to understand why is there a "Terminated due to signal: FLOATING POINT EXCEPTION (8)" error.
If possible, could you please explain why is there an error and how to fix it.
Thank you for your time.
I do not understand the error. Hence, I haven't tried anything
#include <iostream>
using namespace std;
const int ARR_LENGTH =11;
int main() {
int arr[ARR_LENGTH] = {2,3,5,7,11,13,17,19,23,29};
int input =0;
bool isItRight;
bool isItPrime;
cout <<"Input an integer between 1 and 1000" <<endl;
while (isItRight == false){
cin >>input;
if (!(1000 >=input && input >= 1))
isItRight = false;
else
isItRight =true;
if (input<1 || input > 1000 ){
cout <<"Input out of range" <<endl;
cout << "enter a new value: ";
} else if (!input){
cout <<"wrong data type, enter a new value: ";
}
}
for (int i =0; i < ARR_LENGTH; i++){
if (input % arr[i] || input == arr[i])
isItPrime =true;
else
isItPrime =false;
}
if (isItPrime == true){
cout <<"\nThe value "<<input <<" is prime!" <<endl;
} else if (isItPrime == false){
int i =0;
while (i< ARR_LENGTH){
if ((input % arr[i]) == 0 ){
cout <<"\nThe value "<<input <<" is divisible by: "
<< arr[i] <<endl;
}
}
}
return 0;
}
I expected to check prime numbers and with the strategy in place I am not able to output anything.