I've already added this to my solution 2, but maybe you missed my edit: You must change the line
bool p;
in your function division() to bool
p=false;
This gives the correct result.
I should add that the result is not correct when ther division has no remainder: for 150 / 15 I get 9, and for 1500/15 I get 99. But this should be easy to fix.
P.S.: I did
not change the function compare() !
P.P.S.: When using the online compiler at
https://www.onlinegdb.com/online_c++_compiler[
^] your original program runs even without the modification I suggested! It does take a couple of minutes though! Maybe your system is set to terminate processes that run longer than a specific time limit?