Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based on this comment</p> <blockquote> <p>MY PROGRAM AUTOMATICALLY JUMPS UP TWO LINES</p> </blockquote> <p>I may suggest you see this in the debugger. Jumping up 2 lines itself is correct -- you move up on the function stack (i.e. return to the function which called yours -- and it is again <code>sumTotal</code>). So are you sure that after everything is done function really starts from the beginning?</p> <p>One more thing to think about: if initial value of <code>sumInputToString</code> is less than 10 your code will be executed anyway. Do you want it really?</p> <p>And few advices not related with your question directly. It's very difficult to understand what your function should really do. For any complex algorithm (and this may be considered as complex because you use resursion) you must have a good function comment. I would suggest something like this:</p> <blockquote> <p>This function first calculates the sum of all digits in the given number. If the result is less or equal than 9 it is returned. If not, we continue with this sum as a given number.</p> </blockquote> <p>You may also include short sentense why do you need it (because it may seem strange at the first glance):</p> <blockquote> <p>This function can be used to figure out whether some number is divisible by 3 or not.</p> </blockquote> <p>After wtirting such a comment you are starting to understand what the logic should be and may realize that you don't need a recursion here. And transform your code into something like this:</p> <pre><code>// Function comment int CalculateRecursiveSumOfDigits(int val) { while (val &gt; 9) { val = CalculateSumOfDigits(val); // TODO: implement this function } return val; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload