fork download
  1. using static System.Console;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Program {
  6. private static List<Informacao> informacoes = new List<Informacao>();
  7. public static void Main() {
  8. CadNovaPesquisa();
  9. CadNovaPesquisa();
  10. CalculaMedia();
  11. }
  12. public static void CadNovaPesquisa() {
  13. var informacao = new Informacao();
  14. WriteLine("Informe seu salário bruto:");
  15. if (!decimal.TryParse(ReadLine(), out var salBruto)) return;
  16. informacao.SalBruto = salBruto;
  17. WriteLine("Informe a quantidade de filhos:");
  18. if (!int.TryParse(ReadLine(), out var numFilhos)) return;
  19. informacao.NumFilhos = numFilhos;
  20. informacoes.Add(informacao);
  21. }
  22. public static void CalculaMedia() {
  23. var total = informacoes.Sum(x => x.SalBruto);
  24. WriteLine($"TOTAL: {total} MEDIA: {total/informacoes.Count}");
  25. }
  26. }
  27.  
  28. public class Informacao {
  29. public decimal SalBruto { get; set; }
  30. public int NumFilhos { get; set; }
  31. }
  32.  
  33. //https://pt.stackoverflow.com/q/288051/101
Runtime error #stdin #stdout #stderr 0.02s 17072KB
stdin
Standard input is empty
stdout
Informe seu salário bruto:
Informe seu salário bruto:
stderr
Unhandled Exception:
System.DivideByZeroException: Value was either too large or too small for a Decimal.
  at System.Decimal+DecCalc.VarDecDiv (System.Decimal& d1, System.Decimal& d2) [0x0003e] in <6649516e5b3542319fb262b421af0adb>:0 
  at System.Decimal.Divide (System.Decimal d1, System.Decimal d2) [0x00000] in <6649516e5b3542319fb262b421af0adb>:0 
  at System.Decimal.op_Division (System.Decimal d1, System.Decimal d2) [0x00000] in <6649516e5b3542319fb262b421af0adb>:0 
  at Program.CalculaMedia () [0x00043] in <05e5092af3f2425399010b0f28b2b414>:0 
  at Program.Main () [0x0000a] in <05e5092af3f2425399010b0f28b2b414>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.DivideByZeroException: Value was either too large or too small for a Decimal.
  at System.Decimal+DecCalc.VarDecDiv (System.Decimal& d1, System.Decimal& d2) [0x0003e] in <6649516e5b3542319fb262b421af0adb>:0 
  at System.Decimal.Divide (System.Decimal d1, System.Decimal d2) [0x00000] in <6649516e5b3542319fb262b421af0adb>:0 
  at System.Decimal.op_Division (System.Decimal d1, System.Decimal d2) [0x00000] in <6649516e5b3542319fb262b421af0adb>:0 
  at Program.CalculaMedia () [0x00043] in <05e5092af3f2425399010b0f28b2b414>:0 
  at Program.Main () [0x0000a] in <05e5092af3f2425399010b0f28b2b414>:0