// Castulo Jason Quintero CSC5 Chapter 4, pg. 225, #21
//
/*******************************************************************************
* Calculate Area of Selected Shape
* _____________________________________________________________________________
* This program will accept user input for a selected shape and computes the
* area of the shape
* _____________________________________________________________________________
* INPUT
* menuOption : User's menu selection
* numOne : First user input value for shape
* numTwo : Second user input value for shape
*
* OUTPUT
* result : Calculated area of shape
******************************************************************************/
#include <iostream>
#include <cmath>
using namespace std;
int main() {
const float pi = 3.14159; // constant PI
int menuOption; // INPUT - user's menu selection
float numOne; // INPUT - user input value
float numTwo; // INPUT - second user input value
float result; // OUTPUT - result of the calculation
//displaying menu options to user
cout << "Geometry Calcuator\n\n"
"1. Calculate the Area of a Circle\n"
"2. Calculate the Area of a Rectangle\n"
"3. Calculate the Area of a Triangle\n"
"4. Quit" << endl;
cin >> menuOption;
// menu cases depending on option selected by user
switch (menuOption) {
case 1:
cout << "what is the circles radius?: ";
cin >> numOne;
result = pi * (powf(numOne, 2));
cout << "area of the circle is " << result;
break;
case 2:
cout << "\nwhat is the length of the rectangle?: ";
cin >> numOne;
cout << "\nwhat is the width of the rectangle?: ";
cin >> numTwo;
result = numOne * numTwo;
cout << "\nthe area of the rectangle is " << result << endl;
break;
case 3:
cout << "\nwhat is the triangles base?: ";
cin >> numOne;
cout << "\nwhat is the triangles height?: ";
cin >> numTwo;
result = (numOne * numTwo) * .5f;
cout << "\nthe area of the triangle is " << result << endl;
break;
case 4:
cout << "\nEnd program.";
break;
default:
cout << "\nERROR: invalid entry" << endl;
}
return 0;
}