/* 

  AREA2.C : A C program for calculating areas of
            various shapes.

  Barry McMullin
  1st February 1996.

*/

#include <safe-c.h>

void put_floating_point(floating_point_type number)
{
  string_type s;

  floating_point_to_string(s, number);
  put_string(s);
}

floating_point_type get_floating_point(void)
{
  string_type s;

  get_string(s);
  return (string_to_floating_point(s));
}

void do_square(void)
{
  floating_point_type side;

  put_string("Please enter side of square: ");
  side = get_floating_point();
 
  put_string("The area is: ");
  put_floating_point(side * side);
  put_string("\n\n");
}

void do_triangle(void)
{
  floating_point_type height, base;

  put_string("Please enter triangle height: ");
  height = get_floating_point();
  put_string("Please enter triangle base: ");
  base = get_floating_point();

  put_string("The area is: ");
  put_floating_point(0.5 * base * height);
  put_string("\n\n");
}

void do_rectangle(void)
{
  floating_point_type height,length;

  put_string("Please enter rectangle height: ");
  height = get_floating_point();
  put_string("Please enter rectangle length: ");
  length = get_floating_point();

  put_string("The area is: ");
  put_floating_point(length * height);
  put_string("\n\n");
}

void do_circle(void)
{
  floating_point_type radius;

  put_string("Please enter circle radius: ");
  radius = get_floating_point();

  put_string("The area is: ");
  put_floating_point(3.142 * radius *radius);
  put_string("\n\n");
}

void main(void)
{
  string_type shape;

  put_string("Welcome to AREA2.\n");

  put_string("Please enter one of the following shapes:\n");
  put_string("  Triangle\n");
  put_string("  Square\n");
  put_string("  Rectangle\n");
  put_string("  Circle\n\n");

  put_string("Shape: ");
  get_string(shape);

  if (string_equal(shape, "Triangle\n"))
    do_triangle();
  else
    if (string_equal(shape, "Square\n"))
      do_square(); 
    else
      if (string_equal(shape, "Rectangle\n"))
        do_rectangle();
      else
        do_circle();


  put_string("\n\nBye from AREA2!\n");
}
