0
struct estudiante {
    string apellidos ;
    string nombres ;
    int anioIngreso ;
    int anioActual ;
    float promedio ;
} ;

struct recibido {
    string apellidos ;
    string nombres ;
    int anioEgreso ;
    float promedio ;
} ;

bool continuar () ;
bool tipoIngreso () ;
estudiante ingresoEstudiante () ;
recibido ingresoRecibido () ;
estudiante mayorPromedioE (estudiante mayorPromE , estudiante ingresoE) ;
recibido mayorPromedioR (recibido mayorPromR , recibido ingresoR) ;
void display (int cantidad , float sumaPromedios , estudiante mayorPromE , recibido mayorPromR) ;


int main () {
    int cantidad = 0 ;
    bool cont , tipo;
    float sumaPromedios ;
    estudiante ingresoE , mayorPromE = {"" , "" , 0 , 0 , 0};
    recibido ingresoR , mayorPromR = {"" , "" , 0 , 0};
    
    do {
        cantidad++ ;
        tipo = tipoIngreso () ;
        if (tipo = true) {
            ingresoE = ingresoEstudiante () ;
            mayorPromE = mayorPromedioE (mayorPromE , ingresoE) ;
            sumaPromedios += ingresoEstudiante.promedio ;   
        }
        else {
            ingresoR = ingresoRecibido () ;
            mayorPromR = mayorPromedioR (mayorPromR , ingresoR) ;
            sumaPromedios += ingresoRecibido.promedio ; 
        }
            
        cont = continuar () ;   
    } while (cont == true) ; 
    
    display(cantidad , sumaPromedios , mayorPromE , mayorPromR) ;
    
    return 0 ;
}

estudiante ingresoEstudiante () {
    estudiante ingreso ;
    
    cin.ignore() ;
    cout << "Ingrese los datos del estudiante" << endl ;
    
    do {
        cout << "Apellido: " ; getline(cin , estudiante.apellidos) ;
    } while (estudiante.apellidos == "") ;
    
    do {
        cout << "Nombre: " ; getline(cin , estudiante.nombres) ;
    } while (estudiante.nombres == "") ;
    
    do {
        cout << "Año de ingreso (posterior a 2011): " ; cin >> estudiante.anioIngreso ;
    } while (estudiante.anioIngreso <= 2011) ;
    
    do {
        cout << "Año actual (entre 1 y 5): " ; cin >> estudiante.anioActual ;
    } while (estudiante.anioActual < 1 and estudiante.anioActual > 5) ;
    
    do {
        cout << "Promedio: " ; cin >> estudiante.promedio ;
    } while (estudiante.promedio > 10) ;
    
    return ingreso ;    
}

The line that's giving me a problem right now is this one:

sumaPromedios += ingresoEstudiante.promedio ;

What I'm not sure is if you can't pick up a number from a struct (in this case the float promedio) and add it to a variable in main (sumaPromedios). Did i do something wrong or do i have to find a way around this?

The error the compiler is giving me is this one:

"[Error] request for member 'promedio' in 'ingresoEstudiante', which is of non-class type 'estudiante()'"

  • 2
    The error message is pointing out that `ingresoEstudiante` is a function. It doesn't have any members. – cigien Oct 27 '20 at 12:35
  • 1
    Voting to close as a typo. You need to call the function so `sumaPromedios += ingresoEstudiante.promedio` becomes `sumaPromedios += ingresoEstudiante().promedio` – NathanOliver Oct 27 '20 at 12:38
  • @NathanOliver There must be a dupe for this, right? Can't seem to find anything :( – cigien Oct 27 '20 at 12:40
  • Does this answer your question? [Is there any difference between \`List x;\` and \`List x()\`](https://stackoverflow.com/questions/12297021/is-there-any-difference-between-list-x-and-list-x) – underscore_d Oct 27 '20 at 12:46
  • @underscore_d Not really, the dupe has a function declaration where not intended. OP wants the function, they're just using it wrong. – cigien Oct 27 '20 at 12:49

1 Answers1

2
estudiante ingresoEstudiante () ;

The shown code declares ingresoEstudiante to be a function that takes no parameters and returns an estudinate object. That's what this declaration means in C++.

sumaPromedios += ingresoEstudiante.promedio ; 

This line of course appears to access a member called promedio in some object called ingresoEstudiante. Except that it's not an object, but a function.

This is not the only bug in the shown code. I just happen to notice another one.

float sumaPromedios ;

This float value is declared, but not initialized to anything.

sumaPromedios += ingresoEstudiante.promedio ; 

Whether this is a function or an object, this attempts to add something to sumaPromedios. This sumaPromedios has never been initialized to anything, this is undefined behavior and after you fix the compilation error you will likely discover that the resulting value will be junk. You will need to fix this issue, as well.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148
  • 1
    OHHHH omg that happens because i name stuff really similarly! I shoud have put `sumaPromedios += ingresoE.promedio ;` because "ingresoE" is the struct, ingresoEgresados is the function! Thanks dude! Can't believe it was an error this dumb :P – Axel Lutzky Marshall Oct 27 '20 at 12:53
  • This also happens whenever a big pile of code is written first, and only then an attempt is made to compile and test it. Professional programmers don't work this way. We write only a few lines of code at a time, compile, test to make sure they work correctly, then write a few more lines, next. And so on. – Sam Varshavchik Oct 27 '20 at 13:53