Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- const double PI = 3.14159; //Const double means that 3.14159 is const double PI. So just type PI or (const)PI in any function to make it work.
- int getPositiveInt(string message)
- {
- int num = 0;
- do
- {
- cout << message << endl;
- cin >> num;
- }while(num <= 0);
- return num;
- }
- double areaOfCircle(int r)
- {
- return PI * powf(r, 2); //powf() is a function and for it to work you need to add the #include <cmath>
- } //But pow() could work if you change add #include <math.h>
- double volOfSphere(int r)
- {
- return 4/3.0 * PI * powf(r, 3);
- }
- int main()
- {
- int radius = getPositiveInt("Enter a positive integer for the radius of a circle/sphere: ");
- double aCircle = areaOfCircle(radius);
- double vSphere = volOfSphere(radius);
- cout << "The area of a circle that has a radius of " <<
- radius << " is " << aCircle << "." << endl;
- cout << "The volume of a sphere that has a radius of " <<
- radius << " is " << vSphere << "." << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement