0
My code it gets 3 student grades and shows your average, counts the number of approved, failed and who are still on exams and show the average of all.
The problems of my code are the accounting of the situations of students who are not in agreement with the notes that are typed and show the individual average of each student who are also not in agreement.
using System;
namespace TesteRepeticao1
{
class Program8
{
static int Main(string[] args)
{
var alunos = new int[3];
int i, reprovados = 0, exame = 0, aprovados = 0;
double nota1 = 0, nota2 = 0, nota3 = 0, media = 0, mediaclasse = 0, somamedias = 0;
for (i = 0; i <= alunos.Length; i++)
{
Console.Write($"Digite a primeira nota do aluno {i}: ");
nota1 = Convert.ToDouble(Console.ReadLine());
Console.Write($"Digite a segunda nota do aluno {i}: ");
nota2 = Convert.ToDouble(Console.ReadLine());
Console.Write($"Digite a terceira nota do aluno {i}: ");
nota3 = Convert.ToDouble(Console.ReadLine());
media = (nota1 + nota2 + nota3) / 3;
somamedias += media;
Console.WriteLine();
}
for (i = 0; i < alunos.Length; i++)
{
if(media < 5)
{
reprovados++;
}
else if (media >= 5 && media < 7)
{
exame++;
}
else if (media >= 7 && media < 10)
{
aprovados++;
}
}
for (i = 0; i < alunos.Length; i++)
{
Console.WriteLine($"A média do aluno {alunos[i]} é {media}");
}
Console.WriteLine();
mediaclasse = somamedias / 3;
Console.WriteLine($"O total de alunos reprovados é {reprovados}");
Console.WriteLine($"O total de alunos em exame é {exame}");
Console.WriteLine($"O total de alunos aprovados é {aprovados}");
Console.WriteLine($"A média da classe é {mediaclasse}");
Console.ReadKey();
return 0;
}
}
}
Inside the for in line I can replace the
do-whiles
by othersfor
?– Carlos A.
@Carlosa. I think so, as long as it’s nothing fancy.
– Augusto Vasques