Skip to content

Instantly share code, notes, and snippets.

@fabriciosanchez
Last active December 29, 2015 06:48
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 fabriciosanchez/7631212 to your computer and use it in GitHub Desktop.
Save fabriciosanchez/7631212 to your computer and use it in GitHub Desktop.
FazOperacaoMatematica(List<string> Valores, char Operador)
private static string MontaRespostaDaOperacaoMatematica(string Parametro)
{
//Console.WriteLine("O resultado da operaÁ„o matem·tica È: " + Parametro);
//Console.ReadLine();
return Parametro;
}
private static string ValidaEntradaDeOperador(string Operador)
{
while (Operador != "+" && Operador != "-" && Operador != "*" && Operador != "/")
{
Console.WriteLine("Desculpe, mas este operador nao e valido. Informe o operador novamente agora:");
Operador = Console.ReadLine();
}
return Operador;
}
private static double FazOperacaoMatematica(List<string> Valores, char Operador)
{
double Acumulador = 0;
try
{
switch (Operador)
{
case '+':
for (int i = 0; i < Valores.Count-1; i++)
{
Acumulador = Acumulador += Convert.ToDouble(Valores[i]);
}
break;
case '-':
for (int i = 0; i < Valores.Count-1; i++)
{
Acumulador = Acumulador -= Convert.ToDouble(Valores[i]);
}
break;
case '*':
for (int i = 0; i < Valores.Count-1; i++)
{
Acumulador = Acumulador *= Convert.ToDouble(Valores[i]);
}
break;
case '/':
for (int i = 0; i < Valores.Count-1; i++)
{
Acumulador = Acumulador /= Convert.ToDouble(Valores[i]);
}
break;
}
}
catch (DivideByZeroException ex)
{
Console.WriteLine(ex.Message);
}
return Acumulador;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment