quick help... very important!

everything is right except for the circumference it keeps giving me 6.22523e-322..
can someone tell me whats wrong with my code ?

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  //layan zuhair
// U00038258

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

double rad(double l1, double z1, double l2, double z2)
{

    double rad;


    rad = sqrt(pow(l2 - l1,2) + pow(z2 - z1,2));

    return rad ;
}

double area(double rad)
{
    double area;
    double r;
    cout << "The circle's circumference is:" << 2*3.142*r<< endl;
    area = 3.142*pow(rad,2);

    return area;
}


int main ()
{
    double lcent , zcent ; // (l,z) values fo rthe center of the circle
    double lpoint , zpoint ; // (l,z) values for a point on the circle
    double r;


    cout << "Enter the coordinates of the center of the circle : ";
    cin >> lcent >> zcent ;

    cout << "Enter the coordinates of one point on the cirlce : ";
    cin >> lpoint >> zpoint ;

    r = rad(lcent, zcent, lpoint , zpoint); //we called the function rad and assigned r to it so we can use the radius in the area function

    cout << "The circle's radius:" << r<< endl ;
    cout << "The circle's area is:" << area(r) ;

    return 0;
}
Hi @layanM,


warning: variable 'r' is uninitialized when used here [-Wuninitialized]
    cout << "The circle's circumference is:" << 2*3.142*r<< endl;


actually r variable -in function area- has a garbage value;
Topic archived. No new replies allowed.