Identifier not found

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 #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'.

Line 21: Remove the dot after the equals sign.
Last edited on
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.
Last edited on
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?
closed account (E0p9LyTq)
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#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);
}


Arslan7041 wrote:
Line 21: Remove the dot after the equals sign.

That "dot" is a decimal point, misplaced.
Last edited on
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.
Last edited on
That "dot" is a decimal point, misplaced.


Oh, I see. My mistake.
I actually typed this in the back of a bus... Getting a little Car sick.


Looking at phone, computer screen, a television, or reading a book in a bus will make it worse.

Look outside!!!
Topic archived. No new replies allowed.