# Thread: Local Function definitions are illegal.....

1. ## 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

2. I think you need to declare the prototypes above main.

3. Looks like you're missing the closing brace at the end of main

4. I get this error when I add the brace at the end.

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

5. ...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));
}

6. 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.

7. and when I add the brace it gives me this error.

'main' : not all control paths return a value

8. I recommended nothing -- I showed you what you posted.
Originally Posted by Dave_Sinkula
this is what you have

Also, subtracttrig is not the same as subracttrig.

9. 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. No, close the else clause. Or yes -- make the declaration, invocation, and definition all match.

11. 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. 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. I apoligize about the prototyping comment. I was not looking closely.

Popular pages Recent additions