function help

This is a discussion on function help within the C++ Programming forums, part of the General Programming Boards category; howdy folks just one quick question here I put this simple function together and I everytime I try executing it ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    function help

    howdy folks just one quick question here I put this simple function together and I everytime I try executing it I get some funky message saying unresolved external check it out

    Code:
    #include <iostream.h>
    #include <ctype.h>
    
    triangle(float a, float b);
    
    
    void main()
    {
    
    	float a,b;
    	float area;
    
    
    		cout<<char(22);
    		cout<<"Enter the length of the base of the triangle: "; cin>>a;
    		cout<<"Now enter the height: "; cin>>b;
    
    		triangle(a, b);
    	   
    }
    
    void triangle(float a, float b)
    {
    
    	float area;
    	area = .5 * a * b;
    	cout<<"The area of the triangle is: "<<area;	
    
    
    }
    so where is the problem here.

  2. #2
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    I may be wrong, but should you not declare

    "triangle(float a, float b);"

    as "void triangle(float a, float b);"
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    thanx dude

    Dude thats the thing with writing code the tinyest details will bury you if your not careful. Thanx dude

  4. #4
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    Init No problem
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >#include <iostream.h>
    Beware, this header is not a part of the language standard.

    >void main()
    main returns int, it always has.
    My best code is written with the delete key.

  6. #6
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    i.e. use:

    Code:
    #include <iostream>   // not <iostream.h>
    
    int main()   // not void main()
    {...
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

  7. #7
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Code:
    int main()
    {
    
        return 0; // dont forget this
    
    }

  8. #8
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by Vicious
    Code:
    int main()
    {
    
        return 0; // dont forget this
    
    }
    according to the standard, that's not necessary
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  9. #9
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Maybe not but it is good practice just in case you switch to another compiler that does require it. Or if the standard is updated to require it.

    I believe #include <ctype.h> should probably have the .h removed as well. It's also a bit odd you didn't need to use using namespace std;

  10. #10
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by Frobozz
    Maybe not but it is good practice just in case you switch to another compiler that does require it.
    time to get a new compiler

    Quote Originally Posted by Frobozz
    Or if the standard is updated to require it.
    doubt it.

    Quote Originally Posted by Frobozz
    It's also a bit odd you didn't need to use using namespace std;
    not really... using using namespace std; is mildly bad practice...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

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