Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,228 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,895 people online right now. Registration is fast and FREE... Join Now!




function header

 
Reply to this topicStart new topic

function header, i'm getting one error for that help

pascal
15 Mar, 2007 - 07:50 PM
Post #1

New D.I.C Head
*

Joined: 8 Feb, 2007
Posts: 18


My Contributions
[function]

this is the program:
CODE

# include<stdio.h>

int rightangle(int);
int isosceles(int);
int scalene (int);
int equilateral(int);


void main()
{
int AngleA, AngleB, AngleC, rightangle,isosceles,scalene,equilateral;


           printf("Please enter three angles");
           scanf("%d%d%d",&AngleA,&AngleB,&AngleC);


                  
rightangle =  rightangle;

                  isosceles= isosceles;

                  scalene= scalene;

                  equilateral= equilateral;

                  printf("This triangle is %d",rightangle);
                  printf ("this triangle is %d" ,isosceles);
                  printf ("this triangle is %d", scalene);
                  printf ("this triangle is %d", equilateral);


                  
}

int rightangle(int AngleA, int AngleB, int AngleC);
{

int rightangle;

if AngleA,AngleB,AngleC==90{

                rightangle=rightangle;

return rightangle;

}

int isosceles (int AngleA, int AngleB, int AngleC);
{
     int isosceles;


               if AngleA==AngleB{

                   isosceles=isosceles;

               }else{

                   if AngleA==AngleC{

                              isosceles=isosceles;

                   }else{

                       if AngleC==AngleB{

                            isosceles=isosceles;


                       }
                              }
                   }

                   return isosceles;

}

int equilateral (int AngleA, int AngleB, int AngleC);
{
     int equilateral;


     if AngleA,AngleB,AngleC==AngleA,AngleB,AngleC{


                       equilateral=equilateral;


                       return equilateral;

}





and this is the error:

ents and Settings\p.J\triangle.cpp(37) : error C2447: missing function header (old-style formal list?)
C:\Documents and Settings\p.J\triangle.cpp(99) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

triangle.obj - 2 error(s), 0 warning(s)
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Function Header
15 Mar, 2007 - 08:17 PM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,859



Thanked: 50 times
Dream Kudos: 550
My Contributions
the immediate problem is that you don't delcare you functions before main, and then you have semicolons after the function in the definitions...

You need your code to look more like the following...

CODE

//This is a declaration... note the semi-colon.
int myfunc(int arg1, int arg2);

int main()
{
  //you need the declaration to be before any use of the function...
  int i = myfunc(1, 2);
  return i;
}


//This is the definition, note the lack of a semi colon.
int myfunc(int arg1, int arg2)
{
   return arg1 * arg2;
}


Once you fix that you will run into a lot more errors....

you open brackets { and never close them (thus the unexpectend end of file).

an if statement should look like
if (AngleA==90 ||AngleB == 90 ||AngleC==90) {rightangle = 1;}

where '==' means 'is equal to' and '||' means 'or'. The brackets are not needed if you only want to execute one statement, but they make you life much more managable if you get into the habbit of always using them.

the line rightangle=rightangle; has no effect in this code... I assume you wan't something like rightangle=1; which would be like saying that rightangle=true; as in C 0 is false and none zero is (for lack of a better name) true. You have 4 items names rightangle... a global varable, a variable local to main, a function, and a variable local to that function. You only need one. You can do without the global variable as they are an evil trick of the devil sent to cause bugs that make you pull out your hair. The function should be named discriptively like isRightTriangle() so you know what it does.

here is that one function re-written:
CODE

int isRightTriangle(int AngleA, int AngleB, int AngleC)
{
    
    int isRight = 0;
    //Might as well do it right...
    if (AngleA + AngleB + AngleC == 180)
    {
        if (AngleA==90 || AngleB==90 || AngleC==90)
        {
            isRight = 1;
        }
    }
    return isRight;
}

This function will return a 1 if the three angles can discribe a euclidean right triangle, else it will return a 0;

This post has been edited by NickDMax: 15 Mar, 2007 - 08:18 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 02:58PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month