Basically im trying to write a program that reads in the radius of a circle and prints its radius, diameter,circumference and area. It dosent seem that hard but when i input my code....
Expand|Select|Wrap|Line Numbers
- //Write a program that reads in radius of a circle and prints the circle's, diameter, circumference and area
- #include <iostream>
- #include <cmath>
- //declaration of variables
- int main ()
- {
- int radius;
- int diameter;
- int circumference;
- int area;
- int pi;
- //ask user to enter radius of circle
- std::cout <<"Enter the radius (integer number only) of the circle\n";
- std::cin >> radius;
- //assign result
- diameter = radius * 2;
- circumference = pi * diameter;
- area = pi * radius * radius;
- //print results
- std::cout << "The Radius of the circle is" << radius << std::endl;
- std::cout << "The Diameter of the circle is" << diameter << std::endl;
- std::cout << "The Circumference of the circle is" << circumference << std::endl;
- std::cout << "The Area of the circle is" << area << std::endl;
- return 0;
- }
An example of the output im getting when i run the program
when the radius is 5, the circumference is -8, and the area is -20.
And im using microsoft visual
Thanks for any help.