Guys whats wrong with my code .. help!

It's an assignment I have to deliver, I'm so beginner and really need help!

This is the question asked to solve: https://s23.postimg.org/izwxeounv/question.jpg

And this is the code I wrote:


#include <iostream>
#include <cmath>
using namespace std;


double distance (int xd1, int xd2, int yd1, int yd2)
{
double d;
d = sqrt (pow((xd2-xd1),2)+pow((yd2-yd1),2));
return d;
}
double radius (int xr1, int xr2, int yr1, int yr2)
{
double r;
r = distance (xr1, xr2, yr1, yr2);
return r;
}

double circumference (double r)
{
double c;
c = 2*3.14*r;
return c;
}

double area (double r)
{
double rad,a;
rad = radius (xd1, xd2, yd1, yd2);
a = 3.14*pow(rad, 2);
return a;
}

int main()
{
int xd1,yd1,xd2,yd2;
cout<< "Enter the center and a point on the circle like this: X1 Y1 X2 Y2: ";
cin>>xd1>>yd1>>xd2>>yd2;

double r=radius(xd1, xd2, yd1, yd2);

cout<<"The radius = "<<r<<endl;
cout<<"The diameter = "<<r*2<<endl;
cout<<"The circumference = "<<circumference(r)<<endl;
cout<<"The area = "<<area(r);


return 0;
}
1
2
3
4
5
In function 'double area(double)': 
29:15: error: 'xd1' was not declared in this scope 
29:20: error: 'xd2' was not declared in this scope 
29:25: error: 'yd1' was not declared in this scope 
29:30: error: 'yd2' was not declared in this scope

The area function doesn't know what xd1, xd2, yd1, yd2 are.

The code already calculates the radius in the main function and sends it as 'r' to the area function. It doesn't seem like you need to recalculate it as 'rad' in the area function. Just use the value of 'r' that is sent in.

1
2
3
4
5
6
7
double area (double r)
{
double rad,a; 
rad = radius (xd1, xd2, yd1, yd2);
a = 3.14*pow(rad, 2);
return a;
}
Topic archived. No new replies allowed.