Local Function definitions are illegal.....

This is a discussion on Local Function definitions are illegal..... within the C++ Programming forums, part of the General Programming Boards category; Hello everyone this is my first post.I was trying to make tihs program using function and everything seemed to be ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    25

    Local Function definitions are illegal.....

    Hello everyone this is my first post.I was trying to make tihs program using function and everything seemed to be going great....until I compiled. This is just a project I want to work on myself. It's going to be more than what it is now. If anyone can show me what I'm doing wrong please? Thanks. BTW, I'm still a "noob" programmer so cut me a lil slack
    Last edited by Zerohero11; 09-07-2005 at 11:16 PM.

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    I think you need to declare the prototypes above main.

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Looks like you're missing the closing brace at the end of main
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    25
    I get this error when I add the brace at the end.

    warning C4715: 'main' : not all control paths return a value

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    ...using and indenter, this is what you have:
    Code:
    // Pythagorean Theorem //
    // Brandon B //
    // 09/04/05//
    // This Program was designed to solve problems using the Pythagorean Theorem//
    
    
    #include <iostream>
    using namespace std;
    
    #include <math.h>
    
    int trigequation( int,int);
    int subracttrig(int,int);
    
    int main ()
    {
    
       int x;
    
       cout<< " Solve for which leg?" << endl;
       cout <<" 1 for C" << endl;
       cout <<" 2 for A & B " << endl;
    
       cin >> x;
    
       if ( x == 1 )
       {
          int A, B, c,b2;
    
    
          cout<< "Enter side A" << endl;
          cin >> A;
          cout <<" Enter side B"<< endl;
          cin >>c;
    
    
          B = trigequation (A,c);
    
          b2 = sqrt(B);
    
          cout << " size of the leg you entered is" <<""<< b2;
    
    
          cout << c <<""<< "is the angle for side C" << endl;
          system("pause");
          return 0;
    
       }
       else if ( x == 2 )
       {
          int ax,be,c,d;
          cout << "Enter number of side" << endl;
          cin >> ax;
          cout << " Enter number of Hypotenus" << endl;
          cin >>be;
    
          c = subracttrig(ax,be);
    
          d = sqrt(c);
    
          cout <<" The answer for the side you solved is" <<d << endl;
    
          system("pause");
          return 0;
    
    
       }
    
       int trigequation(int A, int c)
       {
          return(pow( A,2) + pow( c,2));
       }
    
       int subtracttrig(int ax, int be)
       {
          return(pow(be,2) - pow(ax,2));
       }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    25
    I recieved this error when doing what you recomended.

    error C2601: 'trigequation' : local function definitions are illegal
    C:\Program Files\Microsoft Visual Studio\MyProjects\Trig Calc\Pythagorean.cpp(75) : error C2601: 'subtracttrig' : local function definitions are illegal
    C:\Program Files\Microsoft Visual Studio\MyProjects\Trig Calc\Pythagorean.cpp(90) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.
    Last edited by Zerohero11; 09-07-2005 at 11:16 PM.

  7. #7
    Registered User
    Join Date
    Sep 2005
    Posts
    25
    and when I add the brace it gives me this error.

    'main' : not all control paths return a value

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    I recommended nothing -- I showed you what you posted.
    Quote Originally Posted by Dave_Sinkula
    this is what you have
    Your answer had already been provided.

    [edit]Also, subtracttrig is not the same as subracttrig.
    Last edited by Dave_Sinkula; 09-07-2005 at 10:47 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #9
    Registered User
    Join Date
    Sep 2005
    Posts
    25
    Quote Originally Posted by Dave_Sinkula
    I recommended nothing -- I showed you what you posted.Your answer had already been provided.
    I'm guessing about the prototyping right?

  10. #10
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    No, close the else clause. Or yes -- make the declaration, invocation, and definition all match.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  11. #11
    Registered User
    Join Date
    Sep 2005
    Posts
    25
    Thanks alot guys I got it to work. I thought it was a major problem when it was just a few small minor errors.

  12. #12
    Registered User
    Join Date
    Sep 2005
    Posts
    25
    The correct program:

    Code:
    #include <iostream>
    using namespace std;
    
    #include <math.h>
    
    int trigequation( int,int);
    int subtracttrig(int,int);
        
    
    int main ()
    {
    
       int x;
       cout << "Welcome to Pythagorean solver " << endl;	
       cout<< " Solve for which leg?" << endl;
       cout <<" 1 for C" << endl;
       cout <<" 2 for A & B " << endl;
    
       cin >> x;
    
       if ( x == 1 )
       {
          int A, B, c,b2;
    
    
          cout<< "Enter side A" << endl;
          cin >> A;
          cout <<" Enter side B"<< endl;
          cin >>c;
    
    
          B = trigequation (A,c);
    
          b2 = sqrt(B);
    
        
          cout << b2 <<":"<< "is the angle for side C" << endl;
          system("pause");
    
          return 0;
    
       }
       else if ( x == 2 )
       {
          int ax,be,c,d;
          cout << "Enter number of side" << endl;
          cin >> ax;
          cout << " Enter number of Hypotenus" << endl;
          cin >>be;
    
          c = subtracttrig(ax,be);
    	  
    
          d = sqrt(c);
    
          cout <<" The answer for the side you solved is:"<<"=" <<d << endl;
    
          system("pause");
          return 0;
    
    
       }
    
       return 0;
    }
       
    int trigequation(int A, int c)
       {
          return(pow( A,2) + pow( c,2));
       }
    
       int subtracttrig(int ax, int be)
       {
          return(pow(be,2) - pow(ax,2));
       }

  13. #13
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    I apoligize about the prototyping comment. I was not looking closely.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 07:54 PM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. local function definitions are illegal
    By curlious in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2003, 05:09 AM

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