title: What am I doing wrong in this hamming code?
body: <p>I got college project for writing humming code. I give the below code which seems OK to me but I got 0 in my paper. Don't know what am I doing wrong here. Just before asking my professor can any I help me to find.</p>
  
  <pre><code>#include &lt;iostream.h&gt;
  #include &lt;math.h&gt;
  
  main(){
    int alp,k;
    do{
      cout&lt;&lt;"\n ****************************************************************";
      cout&lt;&lt;"\n \n";
      cout&lt;&lt;"\n WELCOME TO ERROR DETECTION AND CORRECTION";
      cout&lt;&lt;"\n";
      cout&lt;&lt;"\n THE PROGRAM USES SINGLE BIT CORRECTION METHOD OFHAMMING CODES";
      cout&lt;&lt;"\n \n";
      cout&lt;&lt;"\n ****************************************************************";
      cout&lt;&lt;"\n \n \n 1.ALPHABET \n \n 2.NUMERIC \n \n 3.EXIT \n \n ENTER THECHOICE::";
      cin&gt;&gt; alp;
      if(alp==1){
        int num,err_bito,err_bitn;
        int bit[]={0,0,0,0,0,0,0,0,0,0,0,0};
        int bits[]={0,0,0,0,0,0,0,0,0,0,0,0};
        cout &lt;&lt; "\n \n \n THIS IS CHARACTER ERROR DETECTION ANDCORRECTION PROGRAM";
        char one_char;
        int aq;
        cout &lt;&lt; "\n \n \n \n Enter any a CHARACTER of upper or lower case: ";
        cin &gt;&gt; one_char;
        cout &lt;&lt; "\n \n The character entered was : " &lt;&lt; one_char &lt;&lt; '\n';
        aq=(int) one_char;
        cout &lt;&lt; "\n \n Its ASCII value is : " &lt;&lt; aq &lt;&lt; '\n';
        num=aq;
        bit[1]=num%2;
        int a;
        a=num-num%2;
        int b=a/2;
        bit[2]=b%2;
        a=b-b%2;
        b=a/2;
        bit[3]=b%2;
        a=b-b%2;
        b=a/2;
        bit[4]=b%2;
        a=b-b%2;
        b=a/2;
        bit[5]=b%2;
        a=b-b%2;
        b=a/2;
        bit[6]=b%2;
        a=b-b%2;
        b=a/2;
        bit[7]=b%2;
        a=b-b%2;
        b=a/2;
        bit[8]=b%2;
        a=b-b%2;
        b=a/2;
        bit[9]=b%2;
        a=b-b%2;
        b=a/2;
        bit[10]=b%2;
        a=b-b%2;
        b=a/2;
        bit[11]=b%2;
        a=b-b%2;
        b=a/2;
        cout &lt;&lt; "\n \n The equivalent binary data is:";
        for( k=11;k&gt;0;k--)
          cout &lt;&lt; bit[k];
        cout &lt;&lt; endl;
        int r1,r2,r3,r4,r1o,r2o,r3o,r4o,r1n,r2n,r3n,r4n;
        r1=r2=r3=r4=r1o=r2o=r3o=r4o=r1n=r2n=r3n=r4n=0;
        if(bit[1]==1){
          r1++;
          r2++;
        }
        if(bit[2]==1){
          r1++;
          r3++;
        }
        if(bit[3]==1){
          r2++;
          r3++;
        }
        if(bit[4]==1){
          r1++;
          r2++;
          r3++;
        }
        if(bit[5]==1){
          r1++;
          r4++;
        }
        if(bit[6]==1){
          r2++;
          r4++;
        }
        if(bit[7]==1){
          r1++;
          r2++;
          r4++;
        }
        if(bit[8]==1){
          r3++;
          r4++;
        }
        if(bit[9]==1){
          r1++;
          r3++;
          r4++;
        }
        if(bit[10]==1){
          r2++;
          r3++;
          r4++;
        }
        if(bit[11]==1){
          r1++;
          r2++;
          r3++;
          r4++;
        }
        r1o=r1%2;
        r2o=r2%2;
        r3o=r3%2;
        r4o=r4%2;
        cout&lt;&lt;"\n \n The REDUNDENT BITS are: ";
        cout &lt;&lt; r1o &lt;&lt; r2o &lt;&lt; r3o &lt;&lt; r4o &lt;&lt; endl;
        r1=r2=r3=r4=0;
        int tx_data[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
        int rx_data[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
        cout &lt;&lt;"\n \n Data with REDUNDANT BITS are:";
        tx_data[15]=bit[11];
        cout &lt;&lt; tx_data[15];
        tx_data[14]=bit[10];
        cout &lt;&lt;tx_data[14];
        tx_data[13]=bit[9];
        cout &lt;&lt; tx_data[13];
        tx_data[12]=bit[8];
        cout &lt;&lt; tx_data[12];
        tx_data[11]=bit[7];
        cout &lt;&lt; tx_data[11];
        tx_data[10]=bit[6];
        cout &lt;&lt; tx_data[10];
        tx_data[9]=bit[5];
        cout &lt;&lt; tx_data[9];
        tx_data[8]=r4o;
        cout &lt;&lt;"("&lt;&lt;tx_data[8]&lt;&lt;")";
        tx_data[7]=bit[4];
        cout &lt;&lt; tx_data[7];
        tx_data[6]=bit[3];
        cout &lt;&lt; tx_data[6];
        tx_data[5]=bit[2];
        cout &lt;&lt; tx_data[5];
        tx_data[4]=r3o;
        cout &lt;&lt;"("&lt;&lt; tx_data[4]&lt;&lt;")";
        tx_data[3]=bit[1];
        cout &lt;&lt; tx_data[3];
        tx_data[2]=r2o;
        cout &lt;&lt;"("&lt;&lt; tx_data[2]&lt;&lt;")";
        tx_data[1]=r1o;
        cout &lt;&lt;"("&lt;&lt; tx_data[1]&lt;&lt;")";
        cout&lt;&lt;endl;
        cout &lt;&lt; "\n \n The TRANSMITTED DATA is: ";
        for(k=15;k&gt;0;k--)
          cout &lt;&lt; tx_data[k];
        cout &lt;&lt; endl;
        err_bito=((8*r4o)+(4*r3o)+(2*r2o)+(1*r1o)); // ERROR BIT GENERATED
        for(k=15;k&gt;0;k--)
          rx_data[k]=tx_data[k];
        if(rx_data[err_bito]==1)
          rx_data[err_bito]=0;
        else
          rx_data[err_bito]=1;
        cout &lt;&lt; "\n \n The Received DATA WITH ERROR is:";
        for(k=15;k&gt;0;k--)
          cout &lt;&lt; rx_data[k];
        cout &lt;&lt; endl;
        if(rx_data[3]==1){
          r1++;
          r2++;
        }
        if(rx_data[5]==1){
          r1++;
          r3++;
        }
        if(rx_data[6]==1){
          r2++;
          r3++;
        }
        if(rx_data[7]==1){
          r1++;
          r2++;
          r3++;
        }
        if(rx_data[9]==1){
          r1++;
          r4++;
        }
        if(rx_data[10]==1){
          r2++;
          r4++;
        }
        if(rx_data[11]==1){
          r1++;
          r2++;
          r4++;
        }
        if(rx_data[12]==1){
          r3++;
          r4++;
        }
        if(rx_data[13]==1){
          r1++;
          r3++;
          r4++;
        }
        if(rx_data[14]==1){
          r2++;
          r3++;
          r4++;
        }if(rx_data[15]==1){
          r1++;
          r2++;
          r3++;
          r4++;
        }
        r1n=r1%2;
        r2n=r2%2;
        r3n=r3%2;
        r4n=r4%2;
        r1=r2=r3=r4=0;
        if(r1o==r1n){
          if(r2o==r2n){
            if(r3o==r3n){
              if(r4o==r4n)
                cout &lt;&lt; "\n \n No Error" &lt;&lt; endl;
              else
                cout &lt;&lt; "\n \n Not Possible" &lt;&lt; endl;
            }else{
              if(r4o==r4n)
                cout &lt;&lt; "\n \n Not Possible" &lt;&lt; endl;
              else{
                err_bitn=12;
                cout &lt;&lt; "\n \n Error in bit 12" &lt;&lt; endl;
              }
            }
          }else{
            if(r3o==r3n){
              if(r4o==r4n)
                cout &lt;&lt; "\n \n Not Possible" &lt;&lt; endl;
              else{
                err_bitn=10;
                cout &lt;&lt; "\n \n Error in bit 10" &lt;&lt; endl;
              }
            }else{
              if(r4o==r4n){
                err_bitn=6;
                cout &lt;&lt; "\n \n Error in bit 6" &lt;&lt; endl;
              }else{
                err_bitn=14;
                cout &lt;&lt; "\n \n Error in bit 14" &lt;&lt; endl;
              }
            }
          }
        }else{
          if(r2o==r2n){
            if(r3o==r3n){
              if(r4o==r4n)
                cout &lt;&lt; "\n \n Not Possible" &lt;&lt; endl;
              else{
                err_bitn=9;
                cout &lt;&lt; "\n \n Error in bit 9" &lt;&lt; endl;
              }
            }else{
              if(r4o==r4n){
                err_bitn=5;
                cout &lt;&lt; "\n \n Error in bit 5" &lt;&lt; endl;
              }else{
                err_bitn=13;
                cout &lt;&lt; "\n \n Error in bit 13" &lt;&lt; endl;
              }
            }
          }else{
            if(r3o==r3n){
              if(r4o==r4n){
                err_bitn=3;
                cout &lt;&lt; "\n \n Error in bit 3" &lt;&lt; endl;
              }else{
                err_bitn=11;
                cout &lt;&lt; "\n \n Error in bit 11" &lt;&lt; endl;
              }
            }else{
              if(r4o==r4n){
                err_bitn=7;
                cout &lt;&lt; "\n \n Error in bit 7" &lt;&lt; endl;
              }else{
                err_bitn=15;
                cout &lt;&lt; "\n \n Error in bit 15" &lt;&lt; endl;
              }
            }
          }
        }
        if(rx_data[err_bitn]==1)
          rx_data[err_bitn]=0;
        else
          rx_data[err_bitn]=1;
        cout &lt;&lt; "\n \n The CORRECTED DATA is: ";
        for(k=15;k&gt;0;k--)
          cout &lt;&lt; rx_data[k];
        cout &lt;&lt; endl;
        bits[11]=rx_data[15];
        bits[10]=rx_data[14];
        bits[9]=rx_data[13];
        bits[8]=rx_data[12];
        bits[7]=rx_data[11];
        bits[6]=rx_data[10];
        bits[5]=rx_data[9];
        bits[4]=rx_data[7];
        bits[3]=rx_data[6];
        bits[2]=rx_data[5];
        bits[1]=rx_data[3];
        cout &lt;&lt; "\n \n The Received data withot redundant bit is: ";
        for(k=11;k&gt;0;k--)
          cout &lt;&lt; bits[k];
        cout &lt;&lt; endl;
        double x=2;
        double number=0;
        for(k=11;k&gt;0;k--){
          double z=0;
          z=pow(x, k-1);
          double temp=0;
          temp=bit[k]*z;
          number=number+temp;
        }
        cout &lt;&lt; "\n \n The ALPHABET entered was: " &lt;&lt; one_char &lt;&lt; endl;
      }else{
        if(alp==2){
          int num,numb,err_bito,err_bitn;
          int bit[]={0,0,0,0,0,0,0,0,0,0,0,0};
          int bits[]={0,0,0,0,0,0,0,0,0,0,0,0};
          cout &lt;&lt; "\n \n THIS NUMERIC ERROR DETECTION AND CORRECTIONPROGRAM" &lt;&lt; endl;
          cout&lt;&lt;"\n \n*******************************************************************************";
          cout&lt;&lt;"\n -:CAUTION:- ";
          cout&lt;&lt;"\n \n SINCE THE PROGRAM HAS BEEN DESIGNED FOR 11BITARRAY,THE PROGRAM WILL NOT ACCEPT ANY VALUES GREATER THAN OREQUAL 2048";
          cout&lt;&lt;"\n \n*******************************************************************************";
          cout &lt;&lt; "\n \n \n Enter any decimal number: ";
          cin &gt;&gt; numb;
          if(numb&lt;2048)
            num=numb;
          else{
            cout &lt;&lt; "\n" &lt;&lt; endl;
            cout &lt;&lt; "If u carry on u will get erroneous results" &lt;&lt;endl;
          }
          bit[1]=num%2;
          int a;
          a=num-num%2;
          int b=a/2;
          bit[2]=b%2;
          a=b-b%2;
          b=a/2;
          bit[3]=b%2;
          a=b-b%2;
          b=a/2;
          bit[4]=b%2;
          a=b-b%2;
          b=a/2;
          bit[5]=b%2;
          a=b-b%2;
          b=a/2;
          bit[6]=b%2;
          a=b-b%2;
          b=a/2;
          bit[7]=b%2;
          a=b-b%2;
          b=a/2;
          bit[8]=b%2;
          a=b-b%2;
          b=a/2;
          bit[9]=b%2;
          a=b-b%2;
          b=a/2;
          bit[10]=b%2;
          a=b-b%2;
          b=a/2;
          bit[11]=b%2;
          a=b-b%2;
          b=a/2;
          cout &lt;&lt; "\n \n The equivalent binary data is:";
          for( k=11;k&gt;0;k--)
            cout &lt;&lt; bit[k];
          cout &lt;&lt; endl;
          int r1,r2,r3,r4,r1o,r2o,r3o,r4o,r1n,r2n,r3n,r4n;
          r1=r2=r3=r4=r1o=r2o=r3o=r4o=r1n=r2n=r3n=r4n=0;
          if(bit[1]==1){
            r1++;
            r2++;
          }
          if(bit[2]==1){
            r1++;
            r3++;
          }
          if(bit[3]==1){
            r2++;
            r3++;
          }
          if(bit[4]==1){
            r1++;
            r2++;
            r3++;
          }
          if(bit[5]==1){
            r1++;
            r4++;
          }
          if(bit[6]==1){
            r2++;
            r4++;
          }
          if(bit[7]==1){
            r1++;
            r2++;
            r4++;
          }
          if(bit[8]==1){
            r3++;
            r4++;
          }
          if(bit[9]==1){
            r1++;
            r3++;
            r4++;
          }
          if(bit[10]==1){
            r2++;
            r3++;
            r4++;
          }
          if(bit[11]==1){
            r1++;
            r2++;
            r3++;
            r4++;
          }
          r1o=r1%2;
          r2o=r2%2;
          r3o=r3%2;
          r4o=r4%2;
          cout&lt;&lt;"\n \n The REDUNDENT BITS are: ";
          cout &lt;&lt; r1o &lt;&lt; r2o &lt;&lt; r3o &lt;&lt; r4o &lt;&lt; endl;
          r1=r2=r3=r4=0;
          int tx_data[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
          int rx_data[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
          cout&lt;&lt;"\n \n Data with REDUNDANTS BITS are:";
          tx_data[15]=bit[11];
          cout&lt;&lt; tx_data[15];
          tx_data[14]=bit[10];
          cout&lt;&lt; tx_data[14];
          tx_data[13]=bit[9];
          cout&lt;&lt; tx_data[12];
          tx_data[12]=bit[8];
          cout&lt;&lt; tx_data[12];
          tx_data[11]=bit[7];
          cout&lt;&lt; tx_data[11];
          tx_data[10]=bit[6];
          cout&lt;&lt; tx_data[10];
          tx_data[9]=bit[5];
          cout&lt;&lt; tx_data[9];
          tx_data[8]=r4o;
          cout&lt;&lt;"("&lt;&lt; tx_data[8]&lt;&lt;")";
          tx_data[7]=bit[4];
          cout&lt;&lt; tx_data[7];
          tx_data[6]=bit[3];
          cout&lt;&lt; tx_data[6];
          tx_data[5]=bit[2];
          cout&lt;&lt; tx_data[5];
          tx_data[4]=r3o;
          cout&lt;&lt;"("&lt;&lt; tx_data[4]&lt;&lt;")";
          tx_data[3]=bit[1];
          cout&lt;&lt; tx_data[3];
          tx_data[2]=r2o;
          cout&lt;&lt;"("&lt;&lt; tx_data[2]&lt;&lt;")";
          tx_data[1]=r1o;
          cout&lt;&lt;"("&lt;&lt; tx_data[1]&lt;&lt;")";
          cout&lt;&lt;endl;
          cout &lt;&lt; "\n \n The TRANSMITTED DATA is: ";
          for(k=15;k&gt;0;k--)
            cout &lt;&lt; tx_data[k];
          cout &lt;&lt; endl;
          err_bito=((8*r4o)+(4*r3o)+(2*r2o)+(1*r1o)); // ERROR BIT GENERATED
          for(k=15;k&gt;0;k--)
            rx_data[k]=tx_data[k];
          if(rx_data[err_bito]==1)
            rx_data[err_bito]=0;
          else
            rx_data[err_bito]=1;
          cout &lt;&lt; "\n \n The Received DATA WITH ERROR is:";
          for(k=15;k&gt;0;k--)
            cout &lt;&lt; rx_data[k];
          cout &lt;&lt; endl;
          if(rx_data[3]==1){
            r1++;
            r2++;
          }
          if(rx_data[5]==1){
            r1++;
            r3++;
          }
          if(rx_data[6]==1){
            r2++;
            r3++;
          }
          if(rx_data[7]==1){
            r1++;
            r2++;
            r3++;
          }
          if(rx_data[9]==1){
            r1++;
            r4++;
          }
          if(rx_data[10]==1){
            r2++;
            r4++;
          }
          if(rx_data[11]==1){
            r1++;
            r2++;
            r4++;
          }
          if(rx_data[12]==1){
            r3++;
            r4++;
          }
          if(rx_data[13]==1){
            r1++;
            r3++;
            r4++;
          }
          if(rx_data[14]==1){
            r2++;
            r3++;
            r4++;
          }
          if(rx_data[15]==1){
            r1++;
            r2++;
            r3++;
            r4++;
          }
          r1n=r1%2;
          r2n=r2%2;
          r3n=r3%2;
          r4n=r4%2;
          r1=r2=r3=r4=0;
          if(r1o==r1n){
            if(r2o==r2n){
              if(r3o==r3n){
                if(r4o==r4n)
                  cout &lt;&lt; "\n \n No Error" &lt;&lt; endl;
                else
                  cout &lt;&lt; "\n \n Not Possible" &lt;&lt; endl;
              }else{
                if(r4o==r4n)
                  cout &lt;&lt; "\n \n Not Possible" &lt;&lt; endl;
                else{
                  err_bitn=12;
                  cout &lt;&lt; "\n \n Error in bit 12" &lt;&lt; endl;
                }
              }
            }else{
              if(r3o==r3n){
                if(r4o==r4n)
                  cout &lt;&lt; "\n \n Not Possible" &lt;&lt; endl;
                else{
                  err_bitn=10;
                  cout &lt;&lt; "\n \n Error in bit 10" &lt;&lt; endl;
                }
              }else{
                if(r4o==r4n){
                  err_bitn=6;
                  cout &lt;&lt; "\n \n Error in bit 6" &lt;&lt; endl;
                }else{
                  err_bitn=14;
                  cout &lt;&lt; "\n \n Error in bit 14" &lt;&lt; endl;
                }
              }
            }
          }else{
            if(r2o==r2n){
              if(r3o==r3n){
                if(r4o==r4n)
                  cout &lt;&lt; "\n \n Not Possible" &lt;&lt; endl;
                else{
                  err_bitn=9;
                  cout &lt;&lt; "\n \n Error in bit 9" &lt;&lt; endl;
                }
              }else{
                if(r4o==r4n){
                  err_bitn=5;
                  cout &lt;&lt; "\n \n Error in bit 5" &lt;&lt; endl;
                }else{
                  err_bitn=13;
                  cout &lt;&lt; "\n \n Error in bit 13" &lt;&lt; endl;
                }
              }
            }else{
              if(r3o==r3n){
                if(r4o==r4n){
                  err_bitn=3;
                  cout &lt;&lt; "\n \n Error in bit 3" &lt;&lt; endl;
                }else{
                  err_bitn=11;
                  cout &lt;&lt; "\n \n Error in bit 11" &lt;&lt; endl;
                }
              }else{
                if(r4o==r4n){
                  err_bitn=7;
                  cout &lt;&lt; "\n \n Error in bit 7" &lt;&lt; endl;
                }else{
                  err_bitn=15;cout &lt;&lt; "\n \n Error in bit 15" &lt;&lt; endl;
                }
              }
            }
          }
          if(rx_data[err_bitn]==1)
            rx_data[err_bitn]=0;
          else
            rx_data[err_bitn]=1;
          cout &lt;&lt; "\n \n The CORRECTED DATA is: ";
          for(k=15;k&gt;0;k--)
            cout &lt;&lt; rx_data[k];
          cout &lt;&lt; endl;
          bits[11]=rx_data[15];
          bits[10]=rx_data[14];
          bits[9]=rx_data[13];
          bits[8]=rx_data[12];
          bits[7]=rx_data[11];
          bits[6]=rx_data[10];
          bits[5]=rx_data[9];
          bits[4]=rx_data[7];
          bits[3]=rx_data[6];
          bits[2]=rx_data[5];
          bits[1]=rx_data[3];
          cout &lt;&lt; "\n \n The Recieved data without redundant bit is: ";
          for(k=11;k&gt;0;k--)
            cout &lt;&lt; bits[k];
          cout &lt;&lt; endl;
          double x=2;
          double number=0;
          for(k=11;k&gt;0;k--){
            double z=0;
            z=pow(x, k-1);
            double temp=0;
            temp=bit[k]*z;
            number=number+temp;
          }
          cout &lt;&lt; "\n \n The decimal number entered was:" &lt;&lt; number &lt;&lt; endl;
        }else{
          cout&lt;&lt;"You are quiting from the program";
        }
      }
    }while(alp!=3);
    return(0);
  }
  </code></pre>