title: How do I check for Invalid Binary Inputs
body: <p>I'm having a problem checking for invalid binary inputs from the user. Here is the program. Can anyone tell me how to approach this?</p>
  
  <p>These are the errors I'm getting</p>
  
  <ol>
  <li>error C2660: 'binToDec' : function does not take 1 arguments</li>
  <li>warning C4018: '&lt;' : signed/unsigned mismatch</li>
  <li>error C2082: redefinition of formal parameter 'bin'</li>
  <li>error C2275: 'std::string' : illegal use of this type as an
  expression. see declaration of 'std::string'</li>
  <li><p>error C2082: redefinition of formal parameter 'bin'</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  #include&lt;math.h&gt;
  
  using namespace std;
  
  void intro();
  bool isBinary(string);
  void decToBin();
  string getBin();
  void binToDec();
  char getChoice();
  char getContinue();
  
  int main()
  {
      char choice, cont;
      string bin;
  
      intro();
  
      do{
          choice = getChoice();
              if(choice == 'b' || choice == 'B')
              {
                  bin = getBin();
                  bool binIsBinary = isBinary(bin);
                  if(binIsBinary)
                      binToDec(bin);
                  else
                  {
                      cout&lt;&lt;"Error!!! Your Number is Not Binary"&lt;&lt;endl;
                      cout&lt;&lt;endl;
                  }
              }
  
              if(choice == 'd' || choice == 'B')
                  decToBin();
          cont = getContinue();
        }
      while(cont == 'y' || cont == 'Y');
  }
  
  
  
  void intro()
  { 
      cout &lt;&lt; "This program coverts decimal numbers to binary and vice versa.
               &lt;&lt; endl;
  }
  
  bool isBinary( string bin )
  {
     int i=0;
     bool binIsBinary = true;
  
     while (i &lt; bin.length())
     {
        if( bin.at(i) != '1' &amp;&amp; bin.at(i) != '0' )
            {
            binIsBinary = false;
            }
            i++;
     }
  
     return binIsBinary;
  }
  
  void decToBin()
  {
     int dec;
     string bin;
  
     cout &lt;&lt; endl &lt;&lt; "Please enter a decimal number:"; 
     cin  &gt;&gt;  dec;
     bin = "";
  
     while (dec != 0)
     {
        if (dec % 2 == 0)
           bin.insert(0, "0");
        else
           bin.insert(0, "1");
        dec = dec / 2;
     }
     cout &lt;&lt; "The equivalent binary number is: " &lt;&lt; bin &lt;&lt; endl &lt;&lt; endl;
  
  }
  
  string getBin(string bin)
  {   
      string bin;
  
      cout &lt;&lt; endl &lt;&lt; "Enter a binary number: ";
      cin  &gt;&gt;  bin;
  
      return string;
  }
  
  void binToDec(string bin)
  {
      double deci;
      string bin;
      double len;
  
     len = bin.length();
  
     deci = 0;
     for (int i=0; i&lt;len; i++)
         if (bin.at(i) == '1')
             deci = deci + pow(2, len-i-1);
  
     cout &lt;&lt; "The equivalent decimal number is: " &lt;&lt; deci &lt;&lt; endl    
          &lt;&lt; endl;
  }
  
  char getChoice()
  {
      char choice;
  
      cout &lt;&lt; endl &lt;&lt; "If you would like to convert a binary to a decimal then enter b."&lt;&lt;endl; 
      cout &lt;&lt; "If you would like to convert a decimal to a binary then enter d. ";
      cin &gt;&gt; choice;
  
      return choice;
  }
  
  char getContinue()
  {
      char cont;
  
      cout &lt;&lt; "Would you like to convert another number(Y/N)? ";
  
      cin &gt;&gt; cont;
  
      return cont;
  }
  </code></pre></li>
  </ol>