New way on how to find area of a circle

SO I need to find the area and circumference of a circle right? Normally I can do this in my sleep,but I've learned a new way on how to do this with "class" "public" "private" ect. It runs, but the outcome is not what I want and I don't know why. I followed an example, but with a rectangle instead of a circle to no avail. I just need a second pair of eyes to point out my little mistake.
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
#include <iostream>     
#include <cstdlib>       
using namespace std;

class Circle
{
private:
	double radius;
public:

	void set_radius(double);
	double get_radius() const;
	double get_area() const;
	double get_circumference() const;
};

int main()
{
	Circle rad;
	double radius;
	radius = 0.0;
	cout<<"Enter the radius of a circle"<<endl;
	cin >> radius;

	rad.set_radius(radius);

	cout << "radius: " << rad.get_radius() << endl;
	cout << "Area: " << rad.get_area() << endl;
	cout << "Circumference: " << rad.get_circumference() << endl;
	system("PAUSE");
	return 0;
	

}



void Circle::set_radius(double r)
{
	if (r >= 0)
		r = radius;
	else
	{
		cout << "Invalid number" << endl;
		abort();
	}
		
}

double Circle::get_radius() const
{
	return radius;
}

double Circle::get_area() const
{
	return 3.14*radius*radius;
}

double Circle::get_circumference() const
{
	return 2 * 3.14*radius;
}
On line 41 you wrote r = radius but meant radius = r. Assign the value of the parameter to the member, not the other way around.
Last edited on
Oh! wow now I feel dumb. Thank you for the help man!
Topic archived. No new replies allowed.