lundi 25 septembre 2017

Floating point exception(core dumped) c++

Keep getting a floating point exception for my program. I have variables n, a, and b that are getting inputted by the user. I am only testing part of the program that uses variable n. Originally I solved the problem by making sure I had a cin for variables a and b even though they were not being used. after tinkering with the program its back to giving me the floating point error and I can not seem to figure out why.

the variables being inputted are as follows 
n = 30
a =1
b = 1

#include <iostream>
using std::cout; using std::cin; using std::endl; using std::fixed;


long biggest_prime (long n){
//this function will find the biggest prime factor of a given number N
long biggestPrimeFactor;
long prime_list[100]; 
int count, count2;

 if (n > 1){
     for (int i; i<100;i++ ){
         if(0 ==  n % i){
             prime_list[count]= i;
             n = n / i;
             count++;
         }}}
do {

    biggestPrimeFactor = prime_list[count2];
    count2++;

}while (prime_list[count2] > biggestPrimeFactor);

return biggestPrimeFactor;
}

int main(){
long n;
long a, b;
cin >> n >> a >> b;

long BPF = biggest_prime(n);
cout << BPF << std::endl;

return 0; 
}

Aucun commentaire:

Enregistrer un commentaire