Last active
December 29, 2015 06:48
-
-
Save fabriciosanchez/7631212 to your computer and use it in GitHub Desktop.
FazOperacaoMatematica(List<string> Valores, char Operador)
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
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