title: What am i missing in my C code in order to achieve the right number in Luhn’s Algorithm?
body: <p>I'm new to programming, C and I'm trying to solve CS50's pset1 problem, Luhn's Algorithm to check if a credit card is valid.
  The example I'm using to test is this card Visa: 4003600000000014.</p>
  <pre><code>As referred in the problem, first underline every other digit, starting with the number’s second-to-last digit:
  
  [4] 0 [0] 3 [6] 0 [0] 0 [0] 0 [0] 0 [0] 0 [1] 4
  
  Multiply the underlined digits by 2:
  
  1•2 + 0•2 + 0•2 + 0•2 + 0•2 + 6•2 + 0•2 + 4•2
  
  That gives:
  
  2 + 0 + 0 + 0 + 0 + 12 + 0 + 8
  
  Add those products’ digits (i.e., not the products themselves) together:
  
  2 + 0 + 0 + 0 + 0 + 1 + 2 + 0 + 8 = 13
  </code></pre>
  <pre><code>#include &lt;cs50.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;math.h&gt;
  
  int main(void)
  {
  
      // Variable assignment
      long card;
      int case1, case2, mod, mod2;
  
      // Get input from user
      do
      {
          card = get_long(&quot;Card: &quot;);
      }
      while (card &lt;= 0);
  
      // Case 1
          for (long checksum = card; checksum &gt; 0; checksum = checksum / 10)
      {
  
          mod = remainder(checksum, 10) * 2;
          if (mod &gt;= 10)
          {
              mod2 = remainder (mod, 10);
              case1 = case1 + mod2;
              mod = mod / 10;
              case1 = case1 + mod;
          }
          else
          {
              case1 = case1 + mod;
          }
          checksum = checksum / 10;
          printf(&quot;\n%d&quot;, case1);
      }
  }
  </code></pre>
  <p>My output:</p>
  <pre><code>~/pset1/credit/ $ ./credit 
  Card: 4003600000000014
  
  8
  8
  8
  8
  8
  8
  14
  14
  
  </code></pre>
  <p>The number printed should be 13, for some reason the number my output is printing is 14.
  I've tried to make changes to the code, although i get outputs of 2 and -6. Tried CS50 debug tool too, without success.
  What is my code missing in order to have an output of 13?</p>