How to calculate average students and show in percentage?

Asked

Viewed 214 times

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,inserir a descrição da imagem aquisomeone 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 sorry for the question,?

  • 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%

  • @Bernardolopes sorry Ernardo,?

  • @Bernardolopes understood now what you meant, the problem wants to know only who is above 70, and would you write the code for me ?

  • 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 divides tAlunoAcima/total

  • 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;

  • @Bernardolopes I’ll try here.

  • I’m not very familiar with C#.

Show 4 more comments

2 answers

0

  class Colegio

   {
    static void Main(string[] args)
           {
        //voce nao sabe a quantia de notas que serao dadas então deve informar antes para criar um vetor para elas
        Console.WriteLine("Quantidade de notas a serem inseridas: ");
        int quantidade = int.Parse(Console.ReadLine());
        int i = 0;
        double acimaDaMedia=0;
        double media=0;
        double mediaTotal, porcentagem;
        double[] notas = new double[quantidade];
        //laço para informar as notas
        while (i != quantidade)
        {
            Console.WriteLine("Digite a " +(i+1)+"ª nota");
            notas[i] = Convert.ToDouble(Console.ReadLine());
            i++;
        }
        //laço para somar as notas
        for(int x=0; x< notas.Length; x++)
        {
            media += notas[x];
        }
          //equacao para descobrir o valor da media
        mediaTotal = media / quantidade;
        //laço para descobrir quantos estão acima da media
        for(int x = 0; x < notas.Length; x++) {
            if (notas[x] > mediaTotal)
            {
                acimaDaMedia++;
            }
        }
       //equaçao para saber a porcentagem daqueles que estao acima da media
        porcentagem = (acimaDaMedia* 100) /quantidade;
        Console.WriteLine("a media é: "+ mediaTotal.ToString("F1"));
        Console.WriteLine("a porcentagem é: " + porcentagem.ToString("F3")+"%");
        Console.ReadKey();
    }
}
  • Thank you, I’ll study that code

  • Ok, any doubt or difficulty about the code, just comment here. Good study.

  • If this solution has helped you, mark this answer as accepted so that it is completed. Hug!

0

class Colegio
{
static void Main(){
    double nota1,nota2,nota3,nota4,nota5;
    int totalAluno = 5;
    int tAcima = 0;
    //double[] notas = new double[5];
    int[ ] notas = new int[]{ 50, 50, 70, 80, 100 };

    for (int i = 0; i < 5; i++)
    {
      if(notas[i] > 70){
        tAcima++;
      }
    }
    
    double perAcima = (double) (tAcima/totalAluno);
    double pAcima = perAcima * 100;
    
    double perAbaixo = (double) ( (totalAluno- tAcima) / totalAluno );
    double pAbaixo = perAbaixo * 100;
  }
} 

I couldn’t put Console.Write. I don’t have c# installed

  • @Bernado Lopes thanks anyway. =)

  • @Bernado Lopes I’m new in C# and java programming if you are programming a project with other groups of programmers, include me, my focus at the moment is to learn the most programming.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.