#include <iostream.h>
double box_area(int);
double box_vol(int);

void main()
{   
    int l,w,d;
    double a,v;

    cout<<"length : ";
    cin>>l;
    a=box_area(l);
    cout<<"area : "<<a;

    cout<<"width : ";
    cin>>w;
    a=box_area(w);
    cout<<"area : "<<a;

    cout<<"length : ";
    cin>>l;
    a=box_vol(l);
    cout<<"volume : "<<v;

    cout<<"width : ";
    cin>>w;
    a=box_vol(w);
    cout<<"volume : "<<v;

    cout<<"depth : ";
    cin>>d;
    a=box_vol(d);
    cout<<"volume : "<<v;
}

double box_area(int l);
double box_area(int w);
double box_vol(int l);
double box_vol(int w);
double box_vol(int d)
{
    double area;
    double vol;

    area=l*w;
    vol=l*w*d;

    return area;
    return vol;
}

then I get 2 error that are :-
i) error C2065: 'l' : undeclared identifier
ii)error C2065: 'w' : undeclared identifier

how can I solve it?thanks

you solve it by declaring the variables somewhere. lines 36 to 39 do not declare variables, whose lines are just function prototypes which do nothing except tell the compiler what the function and its parameter types should be.

If I understand what you're trying to do, there are several things that need changing in your code. Try this:

#include <iostream>
using namespace std;
double box_area(int l, int w);
double box_vol(int d, int l, int w);
int main()
{
    int l,w,d;
    double a,v;
    cout<<"length : ";
    cin>>l;
    cout << endl;
    cout<<"width : ";
    cin>>w;
    cout << endl;
    a=box_area(l,w);
    cout<<"area : "<<a << endl << endl;
    cout<<"depth : ";
    cin>>d;
    cout << endl;
    v=box_vol(d,l,w);
    cout<<"volume : "<<v;
    cin.ignore();
    cin.get();
}
double box_area(int l, int w)
{
    double area;
    area = l*w;
    return area;
}
double box_vol(int d, int l, int w)
{
    double vol;
    vol=l*w*d;
    return vol;
}

Edited 3 Years Ago by tinstaafl

In line 40, in your function box_vol, the two identifiers "l" and "w" are strangers there. Once you are inside of the function, there is no way to see outside of it. So any mention of "l" and "w" outside of the function is not observable from within the function, and therefore the identities of these two variables cannot be determined.

Edited 3 Years Ago by MandrewP

i think you declare l,w,d as a global variable and why you make so complex this program it is very simple ..

This article has been dead for over six months. Start a new discussion instead.