//Angel Lugo CSC5 Chapter 4, P. 225, #21
//
/**************************************************************
*
* COMPUTE THE AREA OF CIRCLE, RECTANGLE, AND TRIANGLE
* ____________________________________________________________
* This program computes area of a circle, rectangle, or triangle
* depending on inputs given for each output.
*
* Computation is based on:
* The user's input on the length, width,
* base, height, and radius asked
* for depending on choosen shape
* ____________________________________________________________
* INPUT
* choice: Number 1-4 picked by user
* radius: Radius entered by user
* length: Length entered by user
* width : Width entered by user
* base : Base entered by user
* height: Height entered by user
*
* OUTPUT
* area: Area of shape picked by user
*
**************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//
// Declare variables to store inputs
int choice;
float area;
float radius;
float length;
float width;
float base;
float height;
//
// Loop until 4 is enterd
while (true)
{
//
// Display information in cout
cout << "Geometry Calculator\n\n";
cout << setw(37) << "1. Calculate the Area of a Circle\n"
<< setw(40) << "2. Calculate the Area of a Rectangle\n"
<< setw(39) << "3. Calculate the Area of a Triangle\n"
<< setw(12) << "4. Quit\n\n"
<< setw(28) << "Enter your choice (1-4): ";
//
// Get and Store User input in "cin" for Variable
cin >> choice;
//
// if the if statement is true do statement
if (choice == 4)
{
//
// Exit loop
break;
}
//
// Process choice inputs and continue with items in case
switch (choice)
{
case 1:
cout << "\nWhat is the radius of the circle? \n";
cin >> radius;
if (radius >= 0)
{
area = 3.14159 * (radius * radius);
cout << "The area of the circle is: " << area << "\n";
}
else
{
cout << "\nDo not enter negative values\n";
}
break;
case 2:
cout << "\nWhat is the length of the rectangle? \n";
cin >> length;
cout << "What is the width of the rectangle? \n";
cin >> width;
if (length >= 0 && width >= 0)
{
area = length * width;
cout << "The area of the rectangle is: " << area << "\n";
}
else
{
cout << "\nDo not enter negative values\n";
}
break;
case 3:
cout << "\nWhat is the length of the triangle's base? \n";
cin >> base;
cout << "What is the height of the triangle? \n";
cin >> height;
if (base >= 0 && height >= 0)
{
area = base * height * 0.5;
cout << "The area of the triangle is: " << area << "\n";
}
else
{
cout << "\nDo not enter negative values\n";
}
break;
//
// Display cout if invalid number was entered
default:
cout << "\nInvalid Choice. Enter a number between 1 and 4.\n";
}
cout << "\nClick Enter to Continue\n";
//
// Ignore other key and wait for Enter key to Continue
cin.ignore();
cin.get();
}
return 0;
}