Ad
  • Custom User Avatar

    Thanks for the response! I'll keep the spoilering in mind in the future. Sorry about that!

  • Custom User Avatar

    Well, what happens to binary_sum when the total sum equals to something like 8+4+2+1 or 1? It only contains 1 at the end of the array.

    When you're removing 0s in your result (in the loop there), it got to the point where all 0s is already removed. Then, when it want to search a 0 in the array, it cannot find one. That's why your code is throwing error.

    So, conclusion: You need to fix the if statement in the loop you used for removing leading zeros.

    Next time, use Spoiler flag if you want to send your solution to the discourse. Not a kata issue.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    @hobovsky , that was 100% the problem. I missed it in the example code I even linked to. Thanks for pointing it out!

  • Custom User Avatar

    Did you #include <bitset> in your code?

  • Default User Avatar

    error: no member named 'bitset' in namespace 'std'
    but it's supposed to be there... https://cplusplus.com/reference/bitset/bitset/

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    What is your code?

  • Default User Avatar

    why after I use the str()to print binary result, it still a number like 10? how can i change it like '10'?

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    seems redundant ...

  • Default User Avatar

    because it says "write to the binary string and return it":

    • that is the given string
    • it has been pre-allocated
    • write to it
    • return it
    • profit
  • Default User Avatar

    I dont understand why it returns "You must return a given string" when i allocate memory in the variable "binary" I did the same but without allocating memory and it works, why?

  • Default User Avatar

    Please just forget the IDE, work only with the kata on the codewars site.

    You do not need to, and thus should not, allocate memory. It has already been allocated for you in the provided pointer.

  • Default User Avatar

    I allocated memory in * binary and I store the bits on it and the last line of the fucntion is return binary
    thats all, i dont know why there is always an error or a bug in my code that doesnt seem to have an explanation, C language has been a pain in my head, sometimes the IDe doesn even print the expected result and nothing happens, I have to search deep for some answers before knowing what is the problem.

  • Loading more items...