Public feed
#603814
#include <iostream>#include <math.h>using namespace std;#define PI 3.14159265int main(){int again(void);double pyth(double a, double b);double rpa(int n, double sidelength);double a, b, sidelength;int x, n;double ans;cout << "What math solver would you like to use?\n" << "1. Pythagorean theorem\n" << "2. Regular Polygon Area\n";cin >> x;switch (x){case 1: cout << "What is a?\n"; cin >> a; cout << "What is b?\n"; cin >> b; ans = pyth(a, b); cout << "The hypotenuse is " << ans << " units long.\n\n"; again(); break;case 2: cout << "How many sides are there?\n"; cin >> n; cout << "What is the side length?\n"; cin >> sidelength; ans = rpa(n, sidelength); cout << "The area of the polygon is " << ans << ".\n\n"; again(); break;}return 0;}double pyth(double a, double b){ double aa, bb, cc, c; aa = a * a; bb = b * b; cc = aa + bb; c = sqrt(cc); return c;}double rpa(int n, double sidelength){ double iam, hsl, apothem, area; iam = ((n - 2) * 180) / n; iam /= 2; hsl = sidelength / 2; apothem = hsl * tan(iam*PI/180);; area = 0.5 * ((apothem) * (n * sidelength)); return area;}int again(void){ int main(void); char answer; cout << "Would you like to solve another problem? (y / n)\n"; cin >> answer; switch (answer) { case 'y': main(); break; case 'n': return 0; break; default: again(); break; }}