Area of circle using header file

Write your question here.I am making a program to find the area of circle by using a header file.I a, receiving errors like decleration syntax error and function should return a value and unreachable code AND TOO FEW PARAMETERS TO CALL In to call(int,int)?

code forheader file is
#define pi 3.14
int call(int a,int r)
{
a=pi*r*r*a/a;

return 0;
}


area.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream.h>
#include<conio.h>
#include<area.h>
using namespace std;
int main ()
{
clrscr();
int r;
float a;
call()

cout<<"provide a radius"<<endl;
 cin>>r;
cout<<"the area is"<<a<<endl;
return();

getch();
}
There are a number of errors here. But let's start by getting it to compile.

You should first get the user to supply the radius value, before calling the function.
The function will need to make use of the value of r just entered. You will also need to make use of the value returned from the function.
Hence the code for main might look like this:
1
2
3
4
5
6
    float r;
    cout << "provide a radius " << endl;
    cin >> r;

    float a = call(r);
    cout << "the area is " << a << endl;


Also in main() you have a strange call to a function named return:
 
    return();
that should be
 
    return 0;



Now for the header file.

Well, the function (named call() though I recommend a meaningful name such as area() or circle_area()) is a bit too complicated.

It should accept a single floating point parameter (the radius) and return a floating-point value.
Instead of
 
int call(int a,int r)

I'd suggest perhaps
float area(float r)
note if you change the name to area, make the same change in main()

As for the calculation - well it is just πr2.
You need to do this calculation and then return the calculated result (don't just return zero).

Also - do read the tutorial on using functions:
http://www.cplusplus.com/doc/tutorial/functions/
Last edited on
Topic archived. No new replies allowed.