1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#include <iostream>
using namespace std;
#define pi 3.14159
int main()
{
double which_function;
double r;
double r_squared;
double pi_r;
double area;
double circumference;
cout << "Hello and welcome! This program will allow you to calculate the area and/or circumference of any circle."; cout << endl; cout << endl;
do
{
cout << "Please select which function is required. For area calculations, type 1. For circumference calculations, type 2.";
cout << "For both circumference and area calculations, type 3. To exit program, type 0. Once the number is entered, press return: ";
cin >> which_function;
cout << endl;
if (which_function == 1)
{
do
{
cout << "If circle area is desired, please enter a radius length. Otherwise, to exit area function, enter 0. ";
cout << "Once entered, press the return key: ";
cin >> r; cout << endl;
if (r > 0)
{
r_squared = r * r;
area = r_squared * pi;
cout << "Your radius is: "; cout << r; cout << endl;
cout << "The area of your circle is: "; cout << area; cout << endl; cout << endl;
}
else if (r < 0)
{
cout << "A radius cannot be a negative number. Please try again with a postive number."; cout << endl; cout << endl;
}
}
while (r != 0);
}
else if (which_function == 2)
{
do
{
cout << "If circumference is desired, please enter a radius length. Otherwise, to exit circumference function, enter 0. ";
cout << "Once entered, press the return key: ";
cin >> r; cout << endl;
if (r > 0)
{
pi_r = pi * r;
circumference = 2 * pi_r;
cout << "Your radius is: "; cout << r; cout << endl;
cout << "The circumference of your circle is: "; cout << circumference; cout << endl; cout << endl;
}
else if (r < 0)
{
cout << "A radius cannot be a negative number. Please try again with a postive number."; cout << endl; cout << endl;
}
}
while (r != 0);
}
else if (which_function == 3)
{
do
{
cout << "If circumference and radius are desired, please enter a radius length. Otherwise, to exit circumference and radius function, enter 0. ";
cout << "Once entered, press the return key: ";
cin >> r; cout << endl;
if (r > 0)
{
pi_r = pi * r;
circumference = 2 * pi_r;
r_squared = r * r;
area = r_squared * pi;
cout << "Your radius is: "; cout << r; cout << endl;
cout << "The area of your circle is: "; cout << area; cout << endl;
cout << "The circumference of your circle is: "; cout << circumference; cout << endl; cout << endl;
}
else if (r < 0)
{
cout << "A radius cannot be a negative number. Please try again with a postive number."; cout << endl; cout << endl;
}
}
while (r != 0);
}
else if (which_function == 0)
{
cout << "Thank you for using this program! ";
}
else
{
cout << "You have entered an invalid number. Please try again using no spaces and only numbers 1, 2, 3 or 0."; cout << endl; cout << endl;
}
}
while (which_function != 0);
cout << "Enter any key to exit."; cout << endl;
return 0;
}
|