Programa de datos de alumno, debe de imprimir la media, mediana y moda rede rente a la variable edad .. pero me brinda un error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Programa de datos de alumno, debe de imprimir la media, mediana y moda rede rente a la variable edad .. pero me brinda un error

#include <iostream> #include <cstdlib> #include <windows.h> #include <stdlib.h> using namespace std; struct persona{ string nombre; string apellido; int edad; char genero; }; int main() { cout<<endl<<"|************************************************************************************************|"; cout<<"\n"; cout<<"\t \t \t PROGRAMA DATOS DE ALUMNOS"; cout<<endl<<"|------------------------------------------------------------------------------------------------|"; cout<<"\n"; cout<<"\n"; cout<<"INGRESA EL NOMBRE Y LA EDAD DE 30 ALUMNOS PARA SABER LA MEDIA, MEDIANA Y MODA REFERENTE A LA VARIABLE EDAD: "; cout<<"\n"; cout<<endl<<"|************************************************************************************************|"; cout<<"\n"; { persona Estudiantes[5]; //INGRESO DE LOS DATOS DE LOS ALUMNOS for(int e=0; e<5; e++) { cout<<"ingreso datos alumnos \t"<< e + 1; cout<<"\n"; cout<<"ingreso nombre \t"; cin>>Estudiantes[e].nombre; cout<<"ingreso apellido \t"; cin>>Estudiantes[e].apellido; cout<<"ingreso edad \t"; cin>>Estudiantes[e].edad; cout<<"ingreso genero M/F \t"; cin>>Estudiantes[e].genero; cout<<"\n"; }; int Estudiantes[e].edad; int media, moda, mediana, total; for(int i=0; i<5; i++) { media=total/5; total=Estudiantes[e].edad; cout<<"El calculo de la media es:"; cin>>media; }; for(int j=0; j<5; j++) { mediana= total=Estudiantes[e].edad; cout<<"El calculo de la mediana es:"; cin>>mediana; }; for(int k=0; k<5; k++) { moda= total=total+Estudiantes[e].edad; cout<<"El calculo de la moda es:"; cin>>moda; }; system("pause"); return 0; } } Me brinda error en int Estudiantes [e].edad, espero puedan apoyarme...

1st Nov 2018, 10:11 PM
Cindy Barrios
Cindy Barrios - avatar
8 Answers
0
Your next problem is the value of Total. You declare the variable. And then divide it by 30 It does not have a value yet
1st Nov 2018, 11:24 PM
sneeze
sneeze - avatar
+ 2
so "e" I must put it out of [], as it would be in that case, sorry but I'm new to programming
1st Nov 2018, 10:52 PM
Cindy Barrios
Cindy Barrios - avatar
+ 2
I understood, thank you for explaining that, notice that at the time of running the program asks me to enter the media, mediana and moda .. I do not know if I do something wrong there so that it does not give me the result
1st Nov 2018, 11:15 PM
Cindy Barrios
Cindy Barrios - avatar
+ 2
now my code is like this #include <iostream> #include <cstdlib> #include <windows.h> #include <stdlib.h> using namespace std; struct persona{ string nombre; string apellido; int edad; }; int main() { cout<<"\n"; cout<<"\t \t \t PROGRAMA DATOS DE ALUMNOS"; cout<<endl<<"|--------------------------------------------------------------------------------------------------------|"; cout<<"\n"; cout<<"\n"; cout<<" INGRESA EL NOMBRE Y LA EDAD DE 30 ALUMNOS PARA SABER LA MEDIA, MEDIANA Y MODA REFERENTE A LA VARIABLE EDAD: "; cout<<"\n"; cout<<endl<<"|********************************************************************************************************|"; cout<<"\n"; { persona Estudiantes[30]; //INGRESO DE LOS DATOS DE LOS ALUMNOS for(int e=0; e<30; e++) { cout<<"ingreso datos alumnos \t"<< e + 1; cout<<"\n"; cout<<"ingreso nombre \t"; cin>>Estudiantes[e].nombre; cout<<"ingreso apellido \t"; cin>>Estudiantes[e].apellido; cout<<"ingreso edad \t"; cin>>Estudiantes[e].edad; cout<<"\n"; }; int edad; int media, moda, mediana, total; for(int i=0; i<30; i++) { media=total/30; total=edad; cout<<"El calculo de la media es:"; cin>>media; }; for(int j=0; j<30; j++) { mediana= total=edad; cout<<"El calculo de la mediana es:"; cin>>mediana; }; for(int k=0; k<30; k++) { moda= total=total+edad; cout<<"El calculo de la moda es:"; cin>>moda; }; system("pause"); return 0; } }
1st Nov 2018, 11:19 PM
Cindy Barrios
Cindy Barrios - avatar
+ 1
ok thanks! I try again..
1st Nov 2018, 11:38 PM
Cindy Barrios
Cindy Barrios - avatar
0
Have a look at 'e'. 'e' is a for-loop counter in this line it : "int Estudiantes[e].edad;" It is used outside the loop and the compiler cannot find 'e' for-loop counter only exist within the loop. Also it is used in the i,j,k loop. In these loop you not use i,j,k but 'e'
1st Nov 2018, 10:29 PM
sneeze
sneeze - avatar
0
Please define in small steps what you want to do. Create a list of 5 persons persona Estudiantes[5]; done Ask the use for input for(int e=0; e<5; e++) { cout<<"ingreso datos alumnos \t"<< e + 1; cout<<"\n"; cout<<"ingreso nombre \t"; cin>>Estudiantes[e].nombre; cout<<"ingreso apellido \t"; cin>>Estudiantes[e].apellido; cout<<"ingreso edad \t"; cin>>Estudiantes[e].edad; cout<<"ingreso genero M/F \t"; cin>>Estudiantes[e].genero; cout<<"\n"; }; done Now the list is filled with data and we can calculate with the data. int Estudiantes[e].edad; I do not understand what you want with this line. "int" is the definition a new integer variable. Estudiantes[e].edad is the 0,1,2,3,4 th element of the Estudiantes-array. (depending on the value of 'e') Also this is strange. Here total is divided by 5 before a value is assigned for(int i=0; i<5; i++) { media=total/5; total=Estudiantes[e].edad; cout<<"El calculo de la media es:"; cin>>media; }; Please keep asking questions, you are doing well. It is a way of learning. Read about for-loops and array's
1st Nov 2018, 11:06 PM
sneeze
sneeze - avatar
0
That's part seems to be fine. It will be hard toe execute this in the playground nut on a laptop it is good. Use a for-loop to show the data of the loop after user input.
1st Nov 2018, 11:20 PM
sneeze
sneeze - avatar