Ad
  • Default User Avatar

    Run only the first "Sample Tests" with in your code (just before your return):

    std::cout << sum << "," << NOD << "," << sum / NOD << "," << grandDenom / NOD << std::endl;
    

    and compare the expected result to your printing to see what is wrong in your code.
    To avoid having a big gcd you should first simplify the fractions. On the other hand you could make this first calculation by hand to control your result.

    Update: I added a small utility so that you can view your result and the expected result.