0
I’m trying to create an algorithm in C# as it is in the exercises, in the visual studio, to calculate various average students and show students above average in percentage,I tried a code but this missing put the percentage,someone could help me?
class Colegio
{
static void Main(){
double nota1,nota2,nota3,nota4,nota5,nota6,nota7,nota8,nota9;
double media;
Console.Writeline("Digite a primeira nota":);
nota1=Convert.ToDouble(Console.ReadLine());
Console.Writeline("Digite a segunda nota":);
nota2=Convert.ToDouble(Console.ReadLine());
Console.Writeline("Digite a terceira nota":);
nota3=Convert.ToDouble(Console.ReadLine());
Console.Writeline("Digite a quarta nota":);
nota4=Convert.ToDouble(Console.ReadLine());
Console.Writeline("Digite a quinta nota":);
nota5=Convert.ToDouble(Console.ReadLine());
Console.Writeline("Digite a sexta nota":);
nota6=Convert.ToDouble(Console.ReadLine());
Console.Writeline("Digite a setima nota":);
nota7=Convert.ToDouble(Console.ReadLine());
Console.Writeline("Digite a oitava nota":);
nota8=Convert.ToDouble(Console.ReadLine());
Console.Writeline("Digite a nona nota":);
nota9=Convert.ToDouble(Console.ReadLine());
media = ( nota1 + nota2 + nota3 + nota4 + nota5 + nota6 + nota7 + nota8 + nota9) / 9;
if(media >=70)
{
Console.Writeline("Acima da média");
}
else
{
Console.WriteLine("abaixo da média");
}
Console.ReadKey();
}
}
}
40% = 0.4, for example 40% of 100, you make result = 0.4*100, result = 40
– FourZeroFive
@Fourzerofive sorry for the question,?
– Diana Moura
Your interpretation of the problem is wrong. You are calculating average grades, when you should calculate the number of students with grades > 70. In the sample {50, 50, 70, 80, 100}, there are 2 students with grades > 70 and there are 5 students, so Voce would have to do 2/5 = 0.4 or 40%. And the students below would be 3/5= 0.6 or 60%
– Bernardo Lopes
@Bernardolopes sorry Ernardo,?
– Diana Moura
@Bernardolopes understood now what you meant, the problem wants to know only who is above 70, and would you write the code for me ?
– Diana Moura
Increment a variable to count how many students above the average. and divide by the total of students. You’d need a loop running through each note and checking
if(nota >70){tAlunoAcima ++}
and in the end it only dividestAlunoAcima/total
– Bernardo Lopes
If I understood correctly, the average 70 would be a sample only and the reading of the problem would be: >> media = (Nota1 + nota2 + nota3 + nota4 + nota5 + nota6 + nota7 + nota8 + nota9) / 9 Or total students is 9. After having the average grade, you will need to redeem the grades (Nota1, nota2 etc.) that are/are above this average, add the students who are above the average and then calculate the percentage with the following account: >> percentage = totalAlunosAcimaDaMedia / totalDeNotasAlunos;
– Marcos Xavier
@Bernardolopes I’ll try here.
– Diana Moura
I’m not very familiar with C#.
– Bernardo Lopes