#include <iostream>
Using namespace std;
int main()
{
int height;
int base;
cin>> base >> height;
cout <<"the area is" << area (base, height);
system ("pause") ;
return 0 ;
}
float area(int a, int b)
{
float area;
area=. 5*a*b;
return area;
}
I keep getting an error that the "idsntifier is not found".
You need to include the prototype of the area function above main. The prototype of a function is simply its return type, followed by function name, followed by the parameter types (separated by commas) in parenthesis. Prototypes also end with a semi-colon.
Line 2: "Using namespace std" should be with a lowercase 'u'.
The compiler doesn't know about the name 'area' untill you declare it.
Two possible solutions:
1) Define the area function before the main function. Every definition is also a declaration
2) If you know how to declare a function, declare the area function before the main function.
Tha ks for the replies and just to be clear I actually typed this in the back of a bus... Getting a little Car sick. So some of the mistakes may have just been errors when I was typing my notes on my phone. Anyway could you possibly show me how to define a function in this scenario?
When using a user created function you need to either define the entire function before you can use it, or declare a prototype of the function before use.
Since you are returning a float value from your function why not make all your variables floats. Less conversion errors to possibly deal with.
#include <iostream>
float area(float a, float b);
int main()
{
float height;
float base;
std::cout << "Enter the base and the height: ";
std::cin >> base >> height;
std::cout << "\nThe area is " << area(base, height) << std::endl;
return 0;
}
float area(float a, float b)
{
float area;
area = .5 * a * b;
return area;
}
You could also simplify the area function to something like this:
1 2 3 4
float area(float a, float b)
{
return (.5 * a * b);
}
When using a user created function you need to either declare the entire function before you can use it, or provide a prototype of the function before use.
I know what you ment, but please try to use accurate terminology in order not to confuse a beginner even more.
So, he either needs to DEFINE the entire function before use or he needs to provide a prototype which will declare the function.
Anyway could you possibly show me how to define a function in this scenario?
You have already defined it in your original post. Just move the definition of area function before the definition of the main function.