i am writing a program that has a function call that is just not working. tell me what im doing wrong? thanks
#include <iostream>
using namespace std;
int length_of_side;
int number_of_sides;
int Area (int);
int main ()
{
cout << "enter number of sides" << endl;
cin >> number_of_sides;
cout << "enter length of a side" << endl;
cin >> length_of_side;
cout << "area = " << Area (number_of_sides) << endl;
system ("PAUSE");
return 0;
}
int Area (int number_of_sides, int length_of_side)
{
return (number_of_sides * length_of_side);
}
i get these error messages when i try to compile;
fatal error LNK1120: 1 unresolved externals
error LNK2019: unresolved external symbol "int __cdecl Area(int)" (?Area@@YAHH@Z) referenced in function _main
The signature in your function's declaration ->
int Area (int);
should match the one in its definition ->
int Area (int number_of_sides, int length_of_side)
That is, the former should be ->
int Area (int,int);
Also, you should call your function in main like this ->
Area (number_of_sides,length_of_side)
Finally, since you pass these things as arguments to your function, you don't have to make these
1 2
|
int length_of_side;
int number_of_sides;
|
global variables. Just declare them inside main:
1 2 3 4 5 6 7 8 9
|
int main ()
{
int length_of_side;
int number_of_sides;
//...
return 0;
}
|
Last edited on
Ahh, that makes so much sense. Thanks for the help!!!