using System;
namespace AreaAndPerimeter
{
class Program
{
static void Main(string[] args)
{
ShowMenu();
}
private static void ShowMenu()
{
double PI = Math.PI;
Console.WriteLine("Choose an option:");
Console.WriteLine("");
Console.WriteLine("Press 1 to calculate the area and perimeter of a: CIRCLE.");
Console.WriteLine("Press 2 to calculate the area, perimeter and diagonal of a: RECTANGLE.");
Console.WriteLine("Press 3 to calculate the area, perimeter and diagonal of a: SQUARE.");
Console.WriteLine("Press 4 to calculate the area of a: TRIANGLE.");
Console.WriteLine("Press 5 to exit the program.");
Console.WriteLine("");
int option = Convert.ToInt32(Console.ReadLine());
switch (option)
{
case 1:
Console.WriteLine("");
Console.WriteLine("Insert the radius of the circle.");
double circleRadius = Convert.ToDouble(Console.ReadLine());
double circleArea = PI * circleRadius * circleRadius;
double circlePerimeter = 2 * PI * circleRadius;
Console.WriteLine("The area of the circle is {0:0.00}.", circleArea);
Console.WriteLine("The perimeter of the circle is {0:0.00}.", circlePerimeter);
FinalCase();
break;
case 2:
Console.WriteLine("");
Console.WriteLine("Insert the first side of the reclangle.");
double side1Reclangle = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Insert the second side of the reclangle.");
double side2Rectangle = Convert.ToDouble(Console.ReadLine());
double rectangleArea = side1Reclangle * side2Rectangle;
double rectanglePerimeter = (2 * side1Reclangle) + (2 * side2Rectangle);
Console.WriteLine("The area of the rectangle is {0:0.00}", rectangleArea);
Console.WriteLine("The perimeter of the rectangle is {0:0.00}.", rectanglePerimeter);
double rectangleDiagonal = Math.Sqrt((side1Reclangle * side1Reclangle) + (side2Rectangle * side2Rectangle));
Console.WriteLine("The diagonal of the rectangle is {0:0.00}.", rectangleDiagonal);
FinalCase();
break;
case 3:
Console.WriteLine("");
Console.WriteLine("Inser the side of the square.");
double squareSide = Convert.ToDouble(Console.ReadLine());
double squareArea = squareSide * squareSide;
double squarePerimeter = 4 * squareSide;
Console.WriteLine("The area of the square is {0:0.00}", squareArea);
Console.WriteLine("The perimeter of the square is {0:0.00}.", squarePerimeter);
double squareDiagonal = Math.Sqrt((squareSide * squareSide) + (squareSide * squareSide));
Console.WriteLine("The diagonal of the square is {0:0.00}.", squareDiagonal);
FinalCase();
break;
case 4:
Console.WriteLine("");
Console.WriteLine("Insert a side of a triangle.");
double triangleSide = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Insert its height.");
double triangleHeight = Convert.ToDouble(Console.ReadLine());
double triangleArea = (triangleSide * triangleHeight) / 2;
Console.WriteLine("The area of the triangle is {0:0.00}.", triangleArea);
FinalCase();
break;
case 5:
System.Environment.Exit(1);
break;
default:
Console.WriteLine("");
Console.WriteLine("You havent chosen a valid option.");
Console.WriteLine("--------------------------------------------");
ShowMenu();
break;
}
}
private static void FinalCase()
{
Console.WriteLine("");
Console.WriteLine("--------------------------------------------");
ShowMenu();
}
}
}
Comments