Little Bug

This is a discussion on Little Bug within the C++ Programming forums, part of the General Programming Boards category; I have a little grasshopper I cant catch in my code. Its basic code too, and it looks fine, but ...

  1. #1
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034

    Little Bug

    I have a little grasshopper I cant catch in my code. Its basic code too, and it looks fine, but its returning errors. Basicly its giving errors for not having some variables declared, when they are, but instead of saying they arent declared it freaks out and returns different errors every time it comes across the variables. First it gives syntax error, then it says it has no type and its a declaration, then it says its type is int.

    Triangle.cpp: In member function `bool Triangle::SineLaw()':
    Triangle.cpp:24: error: syntax error before `else'

    Triangle.cpp:27: error: syntax error before `else'

    Triangle.cpp: At global scope:

    Triangle.cpp:30: error: syntax error before `if'
    Triangle.cpp:32: error: ISO C++ forbids declaration of `m_Value_c_Solved' with
    no type
    Triangle.cpp:33: error: syntax error before `}' token
    Triangle.cpp:35: error: ISO C++ forbids declaration of `m_Value_a_Solved' with
    no type
    Triangle.cpp:36: error: syntax error before `}' token
    Triangle.cpp:38: error: ISO C++ forbids declaration of `m_Value_b_Solved' with
    no type
    Triangle.cpp:39: error: syntax error before `}' token
    Triangle.cpp:41: error: ISO C++ forbids declaration of `m_Degree_B_Solved' with

    no type
    Triangle.cpp:42: error: syntax error before `}' token
    Triangle.cpp:44: error: ISO C++ forbids declaration of `m_Degree_C_Solved' with
    no type
    Triangle.cpp:45: error: syntax error before `}' token
    Triangle.cpp:47: error: ISO C++ forbids declaration of `m_Degree_A_Solved' with
    no type
    Triangle.cpp:48: error: syntax error before `}' token
    Triangle.cpp:50: error: ISO C++ forbids declaration of `m_Degree_C_Solved' with
    no type
    Triangle.cpp:50: error: redefinition of `int m_Degree_C_Solved'
    Triangle.cpp:44: error: `int m_Degree_C_Solved' previously defined here
    Triangle.cpp:51: error: syntax error before `}' token
    Triangle.cpp:53: error: ISO C++ forbids declaration of `m_Degree_A_Solved' with
    no type
    Triangle.cpp:53: error: redefinition of `int m_Degree_A_Solved'
    Triangle.cpp:47: error: `int m_Degree_A_Solved' previously defined here
    Triangle.cpp:54: error: syntax error before `}' token
    Triangle.cpp:56: error: ISO C++ forbids declaration of `m_Degree_B_Solved' with
    no type
    Triangle.cpp:56: error: redefinition of `int m_Degree_B_Solved'
    Triangle.cpp:41: error: `int m_Degree_B_Solved' previously defined here
    Triangle.cpp:57: error: syntax error before `}' token

    make.exe: *** [Triangle.o] Error 1

    Execution terminated
    Code:
    class Triangle
    {
    private:
      float m_Value_a;
      float m_Value_b;
      float m_Value_c;
      float m_Degree_A;
      float m_Degree_B;
      float m_Degree_C;
    
      bool m_Value_a_Solved;
      bool m_Value_b_Solved;
      bool m_Value_c_Solved;
      bool m_Degree_A_Solved;
      bool m_Degree_B_Solved;
      bool m_Degree_C_Solved;
    
    public:
      bool SineLaw ();
    
    };
    
    bool Triangle::SineLaw ()
    {
      while (1) {
        if (m_Degree_A != -1 && m_Value_a != -1 && m_Degree_B != -1 && m_Value_b == -1) {
          m_Value_b = m_Degree_B / (m_Degree_A / m_Value_a);
          m_Value_b_Solved = 1; //line 23 (where it starts)
        } if else (m_Degree_A != -1 && m_Value_a != -1 && m_Degree_C != -1 && m_Value_c == -1) {
          m_Value_c = m_Degree_C / (m_Degree_A / m_Value_a);
          m_Value_c_Solved = 1; //error
        } if else (m_Degree_B != -1 && m_Value_b != -1 && m_Degree_A != -1 && m_Value_a == -1) {
          m_Value_a = m_Degree_A / (m_Degree_B / m_Value_b);
          m_Value_a_Solved = 1; //error
        } if else (m_Degree_B != -1 && m_Value_b != -1 && m_Degree_C != -1 && m_Value_c == -1) {
          m_Value_c = m_Degree_C / (m_Degree_B / m_Value_b);
          m_Value_c_Solved = 1; //error
        } if else (m_Degree_C != -1 && m_Value_c != -1 && m_Degree_A != -1 && m_Value_a == -1) {
          m_Value_a = m_Degree_A / (m_Degree_C / m_Value_c);
          m_Value_a_Solved = 1; //error
        } if else (m_Degree_C != -1 && m_Value_c != -1 && m_Degree_B != -1 && m_Value_b == -1) {
          m_Value_b = m_Degree_B / (m_Degree_C / m_Value_c);
          m_Value_b_Solved = 1; //error
        } if else (m_Degree_A != -1 && m_Value_a != -1 && m_Value_b != -1 && m_Degree_B == -1) {
          m_Degree_B = asin((m_Degree_A / m_Value_a) * m_Value_b);
          m_Degree_B_Solved = 1; //error
        } if else (m_Degree_A != -1 && m_Value_a != -1 && m_Value_c != -1 && m_Degree_C == -1) {
          m_Degree_C = asin((m_Degree_A / m_Value_a) * m_Value_c);
          m_Degree_C_Solved = 1; //error
        } if else (m_Degree_B != -1 && m_Value_b != -1 && m_Value_a != -1 && m_Degree_A == -1) {
          m_Degree_A = asin((m_Degree_B / m_Value_b) * m_Value_A);
          m_Degree_A_Solved = 1; //error
        } if else (m_Degree_B != -1 && m_Value_b != -1 && m_Value_c != -1 && m_Degree_C == -1) {
          m_Degree_C = asin((m_Degree_B / m_Value_b) * m_Value_C);
          m_Degree_C_Solved = 1; //error
        } if else (m_Degree_C != -1 && m_Value_c != -1 && m_Value_a != -1 && m_Degree_A == -1) {
          m_Degree_A = asin((m_Degree_C / m_Value_c) * m_Value_A);
          m_Degree_A_Solved = 1; //error
        } if else (m_Degree_C != -1 && m_Value_c != -1 && m_Value_b != -1 && m_Degree_B == -1) {
          m_Degree_B = asin((m_Degree_C / m_Value_c) * m_Value_B);
          m_Degree_B_Solved = 1; //error
        } else {
          return 0;
        }
      }
    
      return 1;
    }
    Any help is appreciated
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  2. #2
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    Remember that it's "else if", not "if else" when you want to chain multiple branches together. And check your capitals, C++ is case sensitive.
    Just because I don't care doesn't mean I don't understand.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    91
    Maybe you should try moving the variable declarations to the public: part of the class? Probably won't work, but hey! :P
    It's Link, not linkofazeroth. The latter's just my username. The former's my online identity. Thank you.

  4. #4
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    Maybe you should try moving the variable declarations to the public: part of the class?
    That won't have any effect. SineLaw is a member function, so it can access the data members regardless of their access level. The problem is that he's using m_Value_A, m_Value_B, and m_Value_C, when the actual declarations are m_Value_a, m_Value_b, and m_Value_c. At least, that's the identifier problem...
    Just because I don't care doesn't mean I don't understand.

  5. #5
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Narf
    Remember that it's "else if", not "if else" when you want to chain multiple branches together. And check your capitals, C++ is case sensitive.
    Oh.. my.. god, I totally missed that.

    Its working, thanks!
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Kernel bug? (attn matsp)
    By brewbuck in forum Linux Programming
    Replies: 7
    Last Post: 04-13-2009, 10:31 AM
  2. gaks bug?
    By Yarin in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-31-2008, 02:47 PM
  3. Debugging a rare / unreproducible bug..
    By g4j31a5 in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 08-05-2008, 12:56 PM
  4. Bug in iterator comparison in C++ standard?
    By steev in forum C++ Programming
    Replies: 14
    Last Post: 07-12-2008, 12:02 AM
  5. ATL bug of CComPtr?
    By George2 in forum Windows Programming
    Replies: 6
    Last Post: 04-07-2008, 07:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21