/*----------------------------------------------------------------------*/
/*                           Area.cpp                                   */
/* Authored By : H.P.Kasmaei                                            */
/* Last Update : March 3, 2009                                          */
/* http://www.hpkclasses.ir/                                            */
/*----------------------------------------------------------------------*/

#include <iostream.h>
 
void menu();
float circle_area(float);
float triangle_area(float, float);
float rectangle_area (float, float);
int main()
{
   // call the menu to cause it to display initially
   menu();
 
   return 1;
 
}// end of main function
void menu()
{
  int menuchoice;
  float radius, height, width, base, answer;
  char somechar;
 
   // This first section simply displays the users choices then 
   // prompts the user to make a selection.
   cout << "1. Area of a circle \n";
   cout << "2. Area of a triangle \n";
   cout << "3. Area of a rectangle \n";
   cout << "4. Exit \n";
   cout << " \n  Please enter the number of your selection \n";
 
   cin >> menuchoice;  // whatever choice the user makes will
                                    //  be stored in the variable menuchoice
 
    // This next section uses a switch case statement to determine the course of action
    // based on what the user chose.
 
    switch (menuchoice)
    {
 
         case 1: // area of circle
                cout << "Please enter the radius of the circle \n";
                cin >> radius;
                answer = circle_area(radius);
                break;
 
         case 2: //area of triangle
                cout << "Please enter the base of the triangle \n";
                cin >> base;
                cout << "Please enter the height of the triangle \n";
                cin >> height;
                answer = triangle_area(base, height);
                break;
 
         case 3: // area of rectangle
                cout << "Please enter the height of the rectangle \n";
                cin >> height;
                cout << "Please enter the width of the rectangle \n";
                cin >> width;
                answer = rectangle_area(height,width);
               break;
   
        case 4: // exit
 
              return;
        default: 
             cout << "Sorry, that was not a valid entry.  Please try again \n";
             menu(); // it redisplays the menu
    }// end of switch
 
    cout << " The answer is " << answer << "\n";
    cout << " Press the enter/return key to continue \n";
 
    menu() ; // redisplay the  menu.
 
}// end of menu function
 
float circle_area(float radius)
{
    float area;
    area = 3.14 * (radius * radius);
    return area;
}
float triangle_area(float height, float base)
{
    float area;
    area = .5 * (base * height);
    return area;}
float rectangle_area(float height, float width)
{
    float area;
    area = height * width;
    return area;
}



