using static System.Console;
using System.Collections.Generic;
using System.Linq;
public class Program {
private static List<Informacao> informacoes = new List<Informacao>();
public static void Main() {
CadNovaPesquisa();
CadNovaPesquisa();
CalculaMedia();
}
public static void CadNovaPesquisa() {
var informacao = new Informacao();
WriteLine("Informe seu salário bruto:");
if (!decimal.TryParse(ReadLine(), out var salBruto)) return;
informacao.SalBruto = salBruto;
WriteLine("Informe a quantidade de filhos:");
if (!int.TryParse(ReadLine(), out var numFilhos)) return;
informacao.NumFilhos = numFilhos;
informacoes.Add(informacao);
}
public static void CalculaMedia() {
var total = informacoes.Sum(x => x.SalBruto);
WriteLine($"TOTAL: {total} MEDIA: {total/informacoes.Count}");
}
}
public class Informacao {
public decimal SalBruto { get; set; }
public int NumFilhos { get; set; }
}
//https://pt.stackoverflow.com/q/288051/101
Standard input is empty
Informe seu salário bruto: Informe seu salário bruto:
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