### Floating point exception ?

This program is supposed to use 3 functions to calculate the factorial of 2 inputs and then find the # of combinations between the two factorials. It compiles correctly but when I run it and put in my inputs the output is "Floating Exception".

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103`` ``````// -------------------------------------------------------------------- // File name: simpleMath.cpp // Assign ID: LAB10 // Due Date: 11/07/12 at 7:30 pm // // Purpose: Performs a simple addiion between 2 items. // // Author: bfields Byron Fields // -------------------------------------------------------------------- #include #include #include using namespace std; int input_check(int n, int r) { if( n > r) return 1; else return 0; } unsigned long int fact(int n, int r,int& a, int& b, int& c) { int factn = 1; do { for (;n>=1;n--) { factn *= n; a = factn; } }while(n != 0); int factr = 1; do { for (;r>=1;r--) { factr *= r; b = factr; } }while(r != 0); c = n-r; } unsigned long int comb(int a, int b, int c, int& combb) { combb = a/(b*c); return combb; } int main() { int n,r,combb; int a; int b; int c; cout << "(c) 2012, bfields Byron Fields" << endl; cout << "Enter the n value" << endl; cin >> n; cout << "Enter the r value" << endl; cin >> r; if(input_check(n,r) == 1) fact(n,r,a,b,c); else cout << "Wrong Input" << endl; comb(a,b,c,combb); cout << a << b << c << combb << endl; cout << "(c) 2012, bfields Byron Fields" << endl; return 0; }``````
Line 66 will fail with a division by zero fault (c will always be 0), which stems from line 58.

Both n and r are 0 at line 58, because you decremented them in the for loops on line 33 and 47.

You can fix this by moving line 58 above the two for loops.
FINALLY... after 4 days i finally got this done. thanks man
Topic archived. No new replies allowed.