How can I calculate the percentage of notes in C #

0
class Alumnos{
    static void Main(string [] args){
        int CantRepro=0, CantApro=0, i=1;
        double promGrupo=0, PromAproba=0, PromDesapro=0, nota=0;
        string resp;

        Console.WriteLine("Desea introducir datos?   S/N");
        resp = Console.ReadLine().ToLower();
        while(resp == "s"){

            Console.WriteLine("Ingrese la nota obtenida");
            nota = Convert.ToDouble(Console.ReadLine());
                if(nota <=5){

                CantRepro++;
            }
            else if(nota >=6){

                CantApro++;
            }
            promGrupo =  nota /nota;

            if(promGrupo>=6){
                PromAproba++;
            }
            else if(promGrupo<=5){
                PromDesapro++;
            }
            i++;

            Console.Write("Desea Continuar  S/N ");
            resp = Console.ReadLine().ToLower();            

        }
        Console.WriteLine("Cantidad de aprobados es:"+CantApro);
        Console.WriteLine("Cantidad de reprobados es:"+CantRepro);
        Console.WriteLine("El promedio grupal es de:"+promGrupo);   
        Console.WriteLine("El promedio aprobado es de:"+PromAproba);
        Console.WriteLine("El promedio desaprobado es de:"+PromDesapro);
    }
}

This is the statement: Calculate the following: a) How many failed. b) How many approved. c) The general average of the group. d) The average of grades passed and failed

Until now I have only been able to do the literals A and B but I do not know how to get the general average of the group and the average of approved and failed grades the rest I do not know if it's okay.

    
asked by Ricardo Alas 05.09.2018 в 22:16
source

2 answers

0

It is an evaluation apparently, there are several options, the simplest with what you have: Declare an integer:

int cantidadNotas = 0; // cada vez que ingreses una nota suma 1

Change this variable to carry the summation

promGrupo =  promGrupo  + nota;

Make the division in the return:

Console.WriteLine("El promedio grupal es de:"+ (promGrupo / cantidadNotas)); 
    
answered by 05.09.2018 в 22:29
0

Is that you are not doing well the logic of the averages, you must have a global accumulator of all the notes and divide them by the number of iterations, and in the other you must take the total of approved and failed and divide them by the number of iterations too:

Here you can do a test .

class Alumnos
{
    static void Main(string[] args)
    {
        int CantRepro=0, CantApro=0, i=0;
        double promGrupo=0, PromAproba=0, PromDesapro=0, nota=0;
        string resp;
        Console.WriteLine("Desea introducir datos?   S/N");
        resp = Console.ReadLine().ToLower();
        while(resp == "s"){
            i++;
            Console.WriteLine("Ingrese la nota obtenida");
            nota = Convert.ToDouble(Console.ReadLine());
            if(nota <=5)
                CantRepro++;
            if(nota >=6)
                CantApro++;
            promGrupo += nota;
            Console.Write("Desea Continuar  S/N ");
            resp = Console.ReadLine().ToLower();
        }
        promGrupo = promGrupo/i;
        PromAproba = ((double)CantApro/i)*100;
        PromDesapro = ((double)CantRepro/i)*100;
        Console.WriteLine("Cantidad de aprobados es:"+CantApro);
        Console.WriteLine("Cantidad de reprobados es:"+CantRepro);
        Console.WriteLine("El promedio grupal es de:"+promGrupo);   
        Console.WriteLine("El promedio aprobado es de:"+PromAproba+"%");
        Console.WriteLine("El promedio desaprobado es de:"+PromDesapro+"%");
    }
}
    
answered by 06.09.2018 в 00:21