Last active
October 3, 2016 22:32
-
-
Save netrac/25bab53338ed7ba0a411f55a190151f6 to your computer and use it in GitHub Desktop.
David a Csharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Main | |
{ | |
class Program | |
{ | |
static double AreaCuadrado() | |
{ | |
Console.WriteLine("Introduzca el lado del cuadrado:"); | |
double d = double.Parse(Console.ReadLine()); | |
if (d <= 0) throw new Exception("El numero no es valido"); | |
return d * d; | |
} | |
static double AreaCirculo() | |
{ | |
Console.WriteLine("Introduzca el radio del circulo:"); | |
double d = double.Parse(Console.ReadLine()); | |
if (d <= 0) throw new Exception("El numero no es valido"); | |
return d * d * Math.PI; | |
} | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Para calcular el area de un cuadrado pulse '1'."); | |
Console.WriteLine("Para calcular el area de un circulo pulse otro numero)."); | |
Console.WriteLine("Introduzca su opción: "); | |
try | |
{ | |
int opcion = Int32.Parse(Console.ReadLine()); | |
if (opcion == 1) | |
{ | |
double resultado = AreaCuadrado(); | |
Console.WriteLine("El area del cuadrado es {0}",resultado); | |
} | |
else | |
{ | |
double resultado = AreaCirculo(); | |
Console.WriteLine("El area del circulo es {0:N10}", resultado); | |
} | |
} | |
catch | |
{ | |
Console.WriteLine("El numero no es valido"); | |
} | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment