title: C - Is there a way to leave a variable unchanged outside of the loop?
body: <p>I've tried searching for the answer to this question, which is a little tricky when you don't know exactly what you're searching for, but here goes.</p>
  
  <p>I'm making my way through CS50 at the moment (very new at this - I know a bit of HTML/CSS and my day job is in marketing). I'm on the final problem of week 1 - I'm making it tricky for myself by doing the harder problems as well as the easy ones, but I'm keen to learn. So far we haven't talked about arrays, which I suspect might be the answer to this question, but without more knowledge I can't be sure.</p>
  
  <p>I'm working on a credit card validator, where I have to do things like get the length of the card number to validate, add different digits etc. Where I'm struggling, is that if I alter a variable inside a loop in some way, when I go to use that variable again, it has the new value in it - not the original one.</p>
  
  <p>How do I store the original value somewhere so it can be accessed without me having to create dozens of new variables to act as placeholders? (Note - the below is just a tiny snippet of my code as an example - I didn't want to include the whole thing)</p>
  
  <p>e.g.</p>
  
  <pre><code>long long credit;           // credit card number
  long long len;              // used to work out len of card number - feeds into count
  
  // validate length of credit card number and get length of card
  
  len = credit;
  while (len &gt; 0)
  {
      len /= 10;
      count ++;
  }
  </code></pre>
  
  <p>In the above example, if I want to use <code>len</code> again further down in my code, it's value will be 0. How do I ensure the original value stays somewhere for me to access in future loops?</p>
  
  <p>I suspect I need to somehow use an array, but so far we've only covered off data types, Booleans, operators, conditional statements and loops (plus <code>printf</code>). All of the info I've found online about arrays talks about needing to specify the array size (the point is I don't know in this example - the values can vary between 13 and 16 digits) and seem more complex than this problem calls for.</p>
  
  <p>I'm pretty sure I'm missing something really simple - I just don't know what it is!</p>
  
  <p>EDIT: Thanks everyone who contributed answers to my very first question! While there may be "better" solutions, it seems that given the constraints I have with my solution specification that I was doing ok and was just overthinking it really. I took the advice from people to copy variables and finally got everything working a few minutes ago.</p>
  
  <p>If anybody would like to see it (although I'm sure my code could do with improvements), my solution is <a href="https://gist.github.com/arianned/693451eca33118017299b7144e1c90ab" rel="nofollow noreferrer">here</a>.</p>
  
  <p>The original specification that I had to meet, was <a href="http://docs.cs50.net/problems/credit/credit.html" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Once again, really appreciated the feedback - I appreciate that this isn't a tutorial site - but sometimes it can be hard to work out what you don't know. Thanks for the help!</p>