46/51 is in no way equal to 23/25
> my algorithm is simplifying the numerator and denominator by dividing with prime numbers
first caveat, you should use the
same factor for both numerator and denominator.
say that your input was 8/9, your algorithm will test 8 by 2 and 9 by 3, that's incorrect
> Prime factors of 46 are 2 and 23 so the count is two, and when I divide 46/2
reduced{Numerator,Denominator} has the
count of prime factors, you divide by the count
suppose your input is 25 = 5*5, you the count is 2 and you do 25/2, that's incorrect.
> So the comparison
if(numerator == denominator)
.
> This is not equal so this fraction is not reducible.
again if your fraction is x/x that's equal 1.
now test your input with 8/2, which is 4
you do the count and have reducedNumerator = 3, reducedDenominator = 1
the division gives you 8/3 == 2/1, which is equal and you enter the if
then you return 3/1... that's incorrect
go back to the drawing board.
Edit:
> and when I divide 46/2 this is where the compiler throws an exception saying integer division by zero.
couldn't reproduce, provide a full testcase.
http://www.eelis.net/iso-c++/testcase.xhtml