Defining a constant & creating double variable with initial value

Define a constant PI that has a value of 3.14159

- Create a double variable, Radius with an initial value of 10

- Create two double variables. Circum and Area, without initialization

- Using the following formulas, compute circumference and area of the circle:

circumference = pi * r * 2 (here, r means radius)

area = pi * r * r

- Display the result using three variables (numbers must come from variables)

- Expected output: (Don’t forget to display the period at the end of the first line)

Circle with radius of 10.

Circumference = 62.8318 Area = 314.159
Ok, where is your code?
This homework is yours, but I had done it. Here it is:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
int main()
{
    const double PI = 3.14159;
    double Radius(10),Circum, Area;
    Circum = PI*Radius*2;
    Area = PI*Radius*Radius;
    std::cout << "Circle with radius of " <<
    Radius << ".\nCircumference = " << Circum <<
    " Area = " << Area;
}
Thanks, I did one similiar to this over a year ago, but I had to cin>>Radius as to where this one is given.
Topic archived. No new replies allowed.