C++ if statement over 4 digits long
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/5715831/c-if-statement-over-4-digits">C++ if statement over 4 digits</a>  </p>
</blockquote>



<p>Hello, im writing a program to convert a four digit octal number to a decimal number. I have to do this programs using charactes. <strong>no char rays or strings says my lecturer.</strong> I need to make thhe code say 'bad data' if the user enters a input number greater than 4 digits. please help. here is my code so far</p>

<pre><code>int main() {

  char a = 0;
  char b = 0;
  char c = 0;
  char d = 0;

  cout &lt;&lt; "Enter 4 digit octal number ";
  cin &gt;&gt; a &gt;&gt; b &gt;&gt; c &gt;&gt; d;
  if (a - '0' &gt; 7 || b - '0' &gt; 7 || c - '0' &gt; 7 || d - '0' &gt; 7 || !isdigit(a)
      || !isdigit(b) || !isdigit(c) || !isdigit(d)) {
    cout &lt;&lt; "Bad data";
  }
  else
    cout &lt;&lt; "Decimal form of that number: " &lt;&lt; ((a - '0') * 512) + ((b - '0')
        * 64) + ((c - '0') * 8) + (d - '0') &lt;&lt; endl;

  return 0;
}
</code></pre>
