it only calculates one circle and i cant fix it
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152`` ``````#include #include class circle{ private: int r,ar,c; public: circle (int r1){r=r1;} int area(){ ar=(r*r*3.14); return ar; } int cir(){ c=(2*3.14*r) ; return c; } void display(){ cout<<"\nFirst circle:\n"; cout<<"area = "<>r1; cout<<"\nEnter the radius of the second circle:\n"; cin>>r2; circle c1(r1); circle c2(r2); circle *c3; c3=&c1,c2; c3->display(); compare(c1,c2); }``````
First, use doubles not ints. There is a problem with functions returning int, but the calculation makes them double implicitly.

Read this for how to deal with doubles:

 http://www.cplusplus.com/forum/beginner/99565/#msg535515

Line 39 is always `int main() { ` if your compiler allows this - it means it is really old like Borland Turbo C++ - get a new one if you can - there are plenty of free ones.

You can avoid using the friend function by providing a public interface to your class. That is, have a public function which returns the value of r.

Hope all goes well.
Change line 6 to `unsigned r;` or `double r;` if you'd like to have a non-integer radius.

Change area to:
 ``1234`` ``````double area() const { return r*r * 3.14 ; }``````

Change cir to:
 ``1234`` ``````double cir() const { return r*2 * 3.14 ; }``````

Most important, change display to:
 ``123`` ``````void display(){ cout << "Area: " << area() << "\nCircumference: " << cir() << '\n' ; }``````

Previously you were just displaying one circle, twice.

Now change main:
 ``1234567891011121314151617181920`` ``````int main(){ int r1,r2; cout<<"Enter the radius of the first circle:\n"; cin>>r1; cout<<"\nEnter the radius of the second circle:\n"; cin>>r2; circle c1(r1); circle c2(r2); circle *c3; c3=&c1,c2; // this is equivalent to c3 = &c1; c2 ; So c3 points to c1 and only c1. c3->display(); // so this will display c1, and only c1. cout << "First circle:\n" ; c1.display() ; cout << "Second circle:\n"; c2.display() ; compare(c1,c2); }``````

@theideasman ,
this question was given to me in my exam so when i asked the instructor why did she ask us to put int instead of double or unsigned she said it was easier for her when grading the exam ,so i just gave in !
and yes i do have turbo borland c++ i did not know there were newer ones since we use the sam one in our lab
also the friend function was a given in the question
lastly thank you very much
@cire thank you know i know where i went wrong !
its always the stupidest things with me :( ,at least i know i wont make the same mistake again . thank you again !
Topic archived. No new replies allowed.