title: Not able to understand how values in loop work
body: <p>I tried writing code for cs50 pset1's problem: credit.c(more comfortable) after week2. My code is given below. The problem is that 'sumx' and 'sumy' are just 0 and hence 'sum' is always equal to 0. So whenever I give a correct credit card number, it is just going to new line and program ends. How can I solve this problem and why are 'sumx' and 'sumy' not adding up to their respective sums as they should according to the algorithm?</p>
  
  <p>My code is:</p>
  
  <pre><code>#include &lt;cs50.h&gt;     
  #include &lt;stdio.h&gt;
  
  int main(void){
  
    long long i;
    do{
      printf("Your credit card number:\n");   
      i = get_long_long();
    }
    while(i &lt; 4e12 || i &gt; 5.5e15);
    int count = 0;
    int n;
    long long c = i;
  
    while(i != 0){
      n = i%10;
      i = i/10;
      count++;
    }
    int x[count];
  
    for(int j = 0; j &lt; count; j++){
      x[j] = c%10;
      i = c/10;
    }
  
    int sumx = 0;
  
    for(int j = 0; j &lt; count - 1; j += 2){
      x[j] = x[j] * 2;
      sumx = sumx + x[j];
      printf("%i", sumx);
    }
  
    int sumy = 0;
  
    for(int j = 0; j &lt; count; j += 2){
      sumy = sumy + x[j];
    }  
  
    int sum;
    sum = sumx + sumy;
  
    if(sum%10 == 0){
      if((count == 15 &amp;&amp; x[14] == 3) &amp;&amp; (x[13] == 4 || x[13] == 7)){
          printf("AmEx\n");
      }
      else if((count == 16 &amp;&amp; x[15] == 5) &amp;&amp; (x[14] &gt; 1 || x[14] &lt; 5)){
          printf("MASTERCARD\n");
      }
      else if((count == 13 &amp;&amp; x[12] == 4) || (count == 16 &amp;&amp; x[15] == 4)){
          printf("VISA\n");
      }
    }
    else{
      printf("Invalid Number\n");
    }
  
    return 0;
    }
  </code></pre>