static void Main(string[] args) { Aluno[] alunos = new Aluno[5]; var indiceAluno = 0; var opcaoUsuario = ObterOpcaoUsuario(); while (opcaoUsuario.ToUpper() != "X") { switch (opcaoUsuario) { case "1": Console.WriteLine("Informe o nome do aluno: "); var aluno = new Aluno(); aluno.Nome = Console.ReadLine(); Console.WriteLine("Informe a nota do aluno"); if (decimal.TryParse(Console.ReadLine(), out decimal nota)) { aluno.Nota = nota; } else { throw new ArgumentException("Valor da nota deve ser decimal"); } alunos[indiceAluno] = aluno; indiceAluno++; break; case "2": foreach (var a in alunos) { if (!string.IsNullOrEmpty(a.Nome)) { Console.WriteLine($"ALUNO: {a.Nome} - NOTA: {a.Nota}"); } } break; case "3": decimal notaTotal = 0; var nrAlunos = 0; for (int i = 0; i < alunos.Length; i++) { if (!string.IsNullOrEmpty(alunos[i].Nome)) { notaTotal = notaTotal + alunos[i].Nota; nrAlunos++; } } var mediaGeral = notaTotal / nrAlunos; Conceito conceitoGeral; if (mediaGeral < 2) { conceitoGeral = Conceito.E; } else if (mediaGeral < 4) { conceitoGeral = Conceito.D; } else if (mediaGeral < 6) { conceitoGeral = Conceito.C; } else if (mediaGeral < 8) { conceitoGeral = Conceito.B; } else { conceitoGeral = Conceito.A; } Console.WriteLine($"MÉDIA GERAL: {mediaGeral} - CONCEITO: {conceitoGeral}"); break; default: throw new ArgumentOutOfRangeException(); } opcaoUsuario = ObterOpcaoUsuario(); } }
static void Main(string[] args) { Aluno[] alunos = new Aluno[5]; var indiceAluno = 0; string opcaoUsuario = ObterOpcaoUsuario(); while (opcaoUsuario.ToUpper() != "X") { switch (opcaoUsuario) { case "1": Console.WriteLine("Informe o nome do aluno:"); var aluno = new Aluno(); aluno.Nome = Console.ReadLine(); Console.WriteLine("Informe a nota do aluno:"); // Conversão da String if (decimal.TryParse(Console.ReadLine(), out decimal nota)) { aluno.Nota = nota; } // // Tratando a exeção else { throw new AggregateException("Valor da nota deve ser decimal"); } // alunos[indiceAluno] = aluno; indiceAluno++; break; case "2": foreach (var a in alunos) { if (!string.IsNullOrEmpty(a.Nome)) //imprime somente se o nome não estiver em branco { Console.WriteLine($" Aluno: {a.Nome} - Nota: {a.Nota}"); } } break; case "3": decimal notaTotal = 0; var nrAlunos = 0; for (int i = 0; i < alunos.Length; i++) { if (!string.IsNullOrEmpty(alunos[i].Nome)) { notaTotal = notaTotal + alunos[i].Nota; nrAlunos++; } } var mediaGeral = notaTotal / nrAlunos; ConceitoEnum conceitoGeral; if (mediaGeral < 2) { conceitoGeral = ConceitoEnum.E; } else if (mediaGeral < 4) { conceitoGeral = ConceitoEnum.D; } else if (mediaGeral < 6) { conceitoGeral = ConceitoEnum.C; } else if (mediaGeral < 8) { conceitoGeral = ConceitoEnum.B; } else { conceitoGeral = ConceitoEnum.A; } Console.WriteLine($" Média Geral: {mediaGeral} - Conceito: {conceitoGeral}"); break; default: throw new ArgumentOutOfRangeException(); } opcaoUsuario = ObterOpcaoUsuario(); } }