Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let me make sure I understand this correctly, your assignment asks for a user input for a given number and store it in <code>num</code> and then display a running sum of 1 up to <code>num</code>?</p> <p>If that's the case, inside your loop you <em>override</em> the user's input of <code>num</code> when you call <code>num = 1</code>. You'll just calculate the running sum of 1-50 every time.</p> <p>To correct that, you need to use a different variable to keep incrementing, i.e. <code>count</code> or the variable <code>i</code> since it's already been declared. Then you should loop up from <code>i</code> to <code>num</code> as long as <code>i &lt;= num</code>.</p> <p>Other than that, I cannot see any problems and it should work correctly.</p> <h3>Note to add about a good investment:</h3> <p>It would definitely be worth while to see if the IDE you are developing in has a <a href="http://www.google.com/#hl=en&amp;q=C%2B%2B+debugger&amp;aq=f&amp;aqi=g1g-c2g1g-c3g3&amp;aql=&amp;oq=&amp;gs_rfai=&amp;fp=a2bb30ecf4f91972" rel="nofollow noreferrer">debugger</a> you can use. Debugging is a great tool to help figure out why your code is not being executing as it is intended to.</p> <p>If there is no debugger (<em>which would surprise me</em>) might I suggest <em>my go-to</em> alternative method of <em>stepping</em> through the <code>for</code> loop on a sheet of paper and compare the <code>sum</code> to another hand-written solution already solved, i.e. <code>num = 5</code> <code>sum = 1+2+3+4+5 = 15</code></p> <p>Hope this helps.</p>
    singulars
    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.
 

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