Ad
  • Default User Avatar

    I just got it now!

    If we store the result of std::sqrt(n) in an int it will disregard the potential decimal numbers (which means the input parameter is not a perfect square to begin with).

    However, storing the result of std::sqrt(n) in an int works for this problem because if you multiply the values stored in the int variable by itself it will NOT equal to the input parameter because the decimal numbers have been taken off. Hence why the function will return false if the input parameter is NOT a perfect square.

  • Default User Avatar

    I don't quite understand why this is accepted? If the square root of n results in a decimal number, then n is not considered a perfect square correct? (and so the function should return false)
    But if we simply store the result of std::sqrt(n) in an int type variable then that disregards the potential decimal digits returned by std::sqrt(n).