x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 617

# Programs that read in the radius of a circle and prints the circle diameter....

Hai there...i need to write a program that reads in the radius of a circle and prints the circle diameter,circumference and area. The constant value is 3.14159 for pie. For example if the user enter 5, then it will shows the result of

Diameter=10
Circumference=31.4159
Area=78.5397

Formula for the circumference and area of circle are C= 2 pie radius and A=pie radius^2
0
inzhagi
• 4
2 Solutions

Commented:
Okay ..i won't give a full code ..
but as i see in your description all you have to do is put what you descriped in small program ..
so first implement the *main* (inside it ask the user to enter the radius of a circle, then save it in a variable say; *Radius* of type double,integer, or float .. )
then add statements specific for each operation (circle diameter, circumeference, and area) ..
not that hard!!
Diameter is calculated by multiply the value by 2 ..
then declare a variable say; *Diatmeter* and assign to it the result of multipling the input value by two ..
then use *cout* function to show the result ..
and do so with others; declare variable and assign to it the result of the mathmatical process .. etc

e.g:

cout<<"The Area is : "<<Area<<endl;

0

Author Commented:
#include <iostream.h>
main()
{

const double pie = 3.14159;
double  r;
double  D;
double  C;
double  A;

cin >> r ;

D = 2*r;
C = 2*pie*r;
A = pie*r*r;

cout <<"Diameter:"<<D<<"D"<<endl;
cout <<"Circumference:"<<C<<"C"<<endl;
cout <<"Area:"<<A<<"A"<<endl;

return 0;

}

i get an error
0

Commented:
what kind of error ??
i ran the code and it give me the expected result !!!
0

Commented:
#include <iostream>
using namespace std;

int main()
{

const double pie = 3.14159;
double  r;
double  D;
double  C;
double  A;

cin >> r ;

D = 2*r;
C = 2*pie*r;
A = pie*r*r;

cout <<"Diameter:"<<D<<"D"<<endl;
cout <<"Circumference:"<<C<<"C"<<endl;
cout <<"Area:"<<A<<"A"<<endl;

return 0;

}
0

Commented:
Venabili ..

I tried to help him to accomplish his homework , and I think the asker respond to my comment and gave a full code for the solution .(I guess he followed the steps I provided in my first comment to write the code),BUT I think he solved the error after posting his code -THAT WHY HE DID NOT POST THE ERROR-.

0

Commented:
Well, Venabili ..
are you going to refund or accept an answer??
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.