compiler error brackets semicolon

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bitbyte89
    New Member
    • Nov 2008
    • 26

    compiler error brackets semicolon

    please tell me wats wrong with this code compiler is giving error in semi colon and curly brackets....

    class snakes
    {
    private:
    int snakesHead[8];
    int snakesTail[8];

    public:

    snakes();
    int isHead(int);

    };


    snakes::snakes( )
    {

    snakesHead[8]={21,36,57,72,7 9,86,92,98};
    snakesTail[8]={2,15,24,49,41 ,54,12,5};

    }

    int snakes::isHead( int head)
    {
    for(int i=0 ; i<8 ; ++i)
    {
    cout<<snakesHea d[i];
    if(head==snakes Head[i])
    return snakesTail[i];

    }

    return -1;
    }
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    You should first of all be able to identify line number in your code that compiler mentioned in error message.

    Comment

    • bitbyte89
      New Member
      • Nov 2008
      • 26

      #3
      class snakes
      {
      private:
      int snakesHead[8];
      int snakesTail[8];

      public:

      snakes();
      int isHead(int);

      };


      snakes::snakes( )
      {

      snakesHead[8]={21,36,57,72,7 9,86,92,98};// here the compiler is giving error
      snakesTail[8]={2,15,24,49,41 ,54,12,5};

      }

      int snakes::isHead( int head)
      {
      for(int i=0 ; i<8 ; ++i)
      {
      cout<<snakesHea d[i];
      if(head==snakes Head[i])
      return snakesTail[i];

      }

      return -1;
      }

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Variable snakesHead is an array of eight ints. snakesHead[8] is an (invalid) element of the array; it represents and int. You can't initialize an int with a list of ints (see your code).

        kind regards,

        Jos

        Comment

        • bitbyte89
          New Member
          • Nov 2008
          • 26

          #5
          class snakes
          {
          private:
          int snakesHead[8];
          int snakesTail[8];

          public:

          snakes();
          int isHead(int);

          };


          snakes::snakes( )
          {

          snakesHead[]={21,36,57,72,7 9,86,92,98};
          snakesTail[]={2,15,24,49,41 ,54,12,5};

          }

          int snakes::isHead( int head)
          {
          for(int i=0 ; i<8 ; ++i)
          {
          cout<<snakesHea d[i];
          if(head==snakes Head[i])
          { return snakesTail[i];
          break;

          }

          }

          return -1;
          }
          still its not workinggiving the same error

          Comment

          • bitbyte89
            New Member
            • Nov 2008
            • 26

            #6
            ok got the answer....


            class snakes
            {
            private:
            int snakesHead[8];
            int snakesTail[8];

            public:

            snakes();
            int isHead(int);

            };


            snakes::snakes( )
            {

            snakesHead[0]=21;
            snakesHead[1]=36;
            snakesHead[2]=57;
            snakesHead[3]=72;
            snakesHead[4]=79;
            snakesHead[5]=86;
            snakesHead[6]=92;
            snakesHead[7]=98;


            snakesTail[0]=2;
            snakesTail[1]=15;
            snakesTail[2]=24;
            snakesTail[3]=49;
            snakesTail[4]=41;
            snakesTail[5]=54;
            snakesTail[6]=12;
            snakesTail[7]=5;

            can't initialize like this......

            // snakesHead[8]={21,36,57,72,7 9,86,92,98};
            // snakesTail[8]={2,15,24,49,41 ,54,12,5};

            }

            int snakes::isHead( int head)
            {
            for(int i=0 ; i<8 ; ++i)
            {
            cout<<snakesHea d[i];
            if(head==snakes Head[i])
            { return snakesTail[i];
            break;

            }

            }

            return -1;
            }

            Comment

            • bitbyte89
              New Member
              • Nov 2008
              • 26

              #7
              thank you so much 4 the help.....

              Comment

              Working...