#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    90
    Rep Power
    11

    function doesn't execute..why..how come?


    Code:
    #include <iostream>
    using namespace std;
    
    void area();
    void main()
    {
    	area();
    	return;
    }
    
    void area()
    {
    	float h,b,art;
    	h=5;
    	b=3.5;
    	art=h*b/2;
    	cout<<"area"<<art;
    	return;
    }
    *edit: added code tags
    *note: start using code tags around your code samples
    Last edited by Onslaught; October 6th, 2003 at 09:24 PM.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,091
    Rep Power
    2222
    Yes it does execute:
    Code:
    C:\dcw\PROJECTS\TEST>cat area2.cpp
    #include <iostream>
    using namespace std;
    
    void area();
    int main()
    {
       area();
        return 0;
    }
    
    void area()
    {
        float h,b,art;
        h=5;
        b=3.5;
        art=h*b/2;
        cout<<"area"<<art;
        return;
    }
    
    
    C:\dcw\PROJECTS\TEST>a
    area8.75
    C:\dcw\PROJECTS\TEST>
    Only change (besides indenting to compensate for your still not using code tags) was to have main declared as int and have it return a 0. gcc wouldn't compile exactly as you had it.
  4. #3
  5. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,074
    Rep Power
    1802
    Strictly main() must be declared as returning int, but it need not explicitly return anything (it is a special case).

    Clifford

IMN logo majestic logo threadwatch logo seochat tools logo