Skip to content

Instantly share code, notes, and snippets.

@AlbertoMonteiro
Created July 28, 2014 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlbertoMonteiro/e25023dc197a793282c7 to your computer and use it in GitHub Desktop.
Save AlbertoMonteiro/e25023dc197a793282c7 to your computer and use it in GitHub Desktop.
Simples calculadora usando scriptcs
public enum Operações
{
Soma = 1,
Subtração,
Multiplicação,
Divisão
}
var type = typeof(Operações);
var todasOperações = Enum.GetNames(type).Select(n => new { Name = n, Value = (int)Enum.Parse(type,n) });
Console.WriteLine("Digite a operação:");
foreach(var a in todasOperações)
Console.WriteLine("{0} => {1}", a.Name, a.Value);
var operação = ((Operações)int.Parse(Console.ReadLine()));
var formato = "O resultado da {0} é {1}";
Tuple<int,int> valores;
int valorFinal;
Func<Tuple<int,int>> capturaValores = () =>
{
Console.WriteLine("Digite o primeiro número");
var valor1 = int.Parse(Console.ReadLine());
Console.WriteLine("Digite o segundo número");
var valor2 = int.Parse(Console.ReadLine());
return new Tuple<int,int>(valor1,valor2);
};
valores = capturaValores();
switch(operação)
{
case Operações.Soma:
valorFinal = valores.Item1 + valores.Item2;
break;
case Operações.Subtração:
valorFinal = valores.Item1 - valores.Item2;
break;
case Operações.Multiplicação:
valorFinal = valores.Item1 * valores.Item2;
break;
case Operações.Divisão:
valorFinal = valores.Item1 / valores.Item2;
break;
}
Console.WriteLine(formato, Enum.GetName(type, operação), valorFinal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment