|
I am a beginner in C++ programming & I use Microsoft visual studio.net 2003 as my compiler.
I wrote the following simple program for area of a triangle
#include<iostream>
int main()
{
int breadth,height;
int area;
std::cout<< "Enter the breadth";
std::cin>>breadth;
std::cout<< "Enter the height";
std::cin>>height;
area = TriangleArea(breadth,height);
std::cout<<"Area of the triangle is:"<<area;
return 0;
}
int TriangleArea(int b,int h)
{
return 0.5 (b*h);
}
On debugging in showed the following errors
c:\My Documents\Visual Studio Projects\C++\Function\Area of triangle.cpp(17): error C3861: 'TriangleArea': identifier not found, even with argument-dependent lookup
c:\My Documents\Visual Studio Projects\C++\Function\Area of triangle.cpp(26): error C2365: 'TriangleArea' : redefinition; previous definition was a 'formerly unknown identifier'
How do I solve the following errors? Do I need to include any header files?
Thanks
<Added>
I have figured out my error.....forgot to define function at the beginning.
<Added>
#include<iostream>
int TriangleArea(int b,int h);//function prototype...that's what I missed in the above program
int main() // rest of the code as above
{
int breadth,height;
------
-------
|
|
|
Why are you using integers? If somebody inputs the numbers 3 and 5, the area is 7.5.
|
|
|
I used intergers only for my convinence.You can ofcourse change the variable type to float.
|
|
|
Have you tried using a forward declaration my friend? In other words:
putting:
int TriangleArea(int, int);
before the main function?
Try that out. I guess it should help.
|
|
|
|
|
|
|
// |