doubt about this code

0

referring to this code to calculate notes, but I have the second doubts, I know that the n is like a liminator (it's worth 2) but what does the aux and the n1 do?

#include<iostream>
#include<conio.h>
using namespace std;
struct alumno
{   char nombre[100];
    double t1, t2, ep, ef;
};
double promAula(alumno A[], int n, double aux,int n1){
    if (n == 0)
        return aux/ n1;
    else {
        double p = A[n - 1].t1*0.15 + A[n - 1].t2*0.15 +
            A[n - 1].ep*0.3 + A[n - 1].ef*0.4;
        aux += p;
        return promAula(A, n - 1, aux, n1);
    }
}
void main(){
alumno A[5]; 
int n = 2; 
double pa = 0;
    for (int i = 0; i < n; i++){
        cout << "Nombre: "; cin >> A[i].nombre;
        cout << "T1: "; cin >> A[i].t1;
        cout << "T2: "; cin >> A[i].t2;
        cout << "EP: "; cin >> A[i].ep;
        cout << "EF: "; cin >> A[i].ef;
    }
    cout << "Promedio Aula: " << promAula(A, n, pa, n);
    _getch();
}
    
asked by Marco Ruiz Navarro 27.09.2018 в 23:25
source

1 answer

1

Well, I'll tell you:

In your code, the aux variable works like a counter that stores the notes of each student and adds them. And, variable n1 works as a student accountant, it does not increase or anything, but it stores the number of students that there are.

When the recursive function finishes analyzing the students structure, what it does is return aux / n1, which is translated as, the sum of all the students' grades, divided by the number of students that there are.

    
answered by 28.09.2018 в 00:06