Cout Result

I would like to display as follows:


Circle (4.67, 28.65, 66.75)

----------------------------
How do I cout using....

cout << "Circle: (" <<

4.67 = radius
28.65 = circumference
66.75 = area

Need to display these functions:

double rad = radius(x1,y1,x2,y2);

double cir = circumference(rad);

double getArea = area(rad);
Did you try std::cout << "Circle: (" << rad << ", " << cir << ", " << getArea << ")" << std::endl;
Can you show in C++?
I tried your mtd. How come?

But got this as output:

Circle (Infinity, Infinity, Infinity)
Pls assist.
FYI, that was C++.

Your functions are probably incorrect, or you didn't initialize your variables correctly.
My former 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;


const float PI = 3.1416;


//Prototypes declaration
double distance (double, double, double, double);
double radius (double, double, double, double);
double circumference (double);
double area (double);


//Main Function
int main()
{

double x1, x2, y1, y2;


//Get a center point
cout << "Enter center of circle: ";

cin >> x1 >> y1;

//Get another point on the circle
cout<<"Enter a point on circle: ";

cin >> x2 >> y2;
double rad = radius(x1,y1,x2,y2);
cout << endl;
double cir = circumference(rad);
cout << endl;
double GetArea = area(rad);
cout << endl;

return 0;

}



double distance (double x1, double y1, double x2, double y2)
{
    double radius = sqrt(pow(x2 - x1 , 2.0)
                    + pow(y2 - y1, 2.0));
    
    return radius;
}



double radius (double x1, double y1, double x2, double y2)
{

    double radius = distance (x1, y1, x2, y2);

    return radius;
}




double circumference (double radius)
{
    double circumference = PI * (radius * 2);

    return circumference;
}


double area(double radius)
{
   double area = PI * radius * radius;
   
   return area;
}
Can assist to display in this format: Circle (4.67, 28.65, 66.75)
Well what's the problem? You are just output endl over and over. Use the line of code that I gave you and put it after you set the last variable in question. Step with the debugger and also verify that the values are correct. What data did you enter? Were the points valid?
I think you just simply forgot to put std::cin.get(); in your codes.. So i think here it is..


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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;


const float PI = 3.1416;


//Prototypes declaration
double distance (double, double, double, double);
double radius (double, double, double, double);
double circumference (double);
double area (double);


//Main Function
int main()
{

double x1, x2, y1, y2;


//Get a center point
cout << "Enter center of circle: ";

cin >> x1 >> y1;

//Get another point on the circle
cout<<"Enter a point on circle: ";

cin >> x2 >> y2;
double rad = radius(x1,y1,x2,y2);
cout << endl;
double cir = circumference(rad);
cout << endl;
double GetArea = area(rad);
cout << endl;
cin.get();


cout<<"Circle("<<rad<<","<<cir<<","<<GetArea<<")"<<endl;
cin.get();

return 0;

}



double distance (double x1, double y1, double x2, double y2)
{
    double radius = sqrt(pow(x2 - x1 , 2.0)
                    + pow(y2 - y1, 2.0));
    
    return radius;
}



double radius (double x1, double y1, double x2, double y2)
{

    double radius = distance (x1, y1, x2, y2);

    return radius;
}




double circumference (double radius)
{
    double circumference = PI * (radius * 2);

    return circumference;
}


double area(double radius)
{
   double area = PI * radius * radius;
   
   return area;
}


Check it out :)

Regards,
Nemesis
Topic archived. No new replies allowed.