Dev - C++ - Ayuda con struct anidadas por favor en mi codigo

 
Vista:
Imágen de perfil de Jorge Jhonnyer
Val: 8
Ha aumentado su posición en 3 puestos en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

Ayuda con struct anidadas por favor en mi codigo

Publicado por Jorge Jhonnyer (4 intervenciones) el 01/10/2018 23:08:43
Buen dia a todos.
Lo que sucede es que he intentado varias veces solucionar un error que sucede en mi código esto es lo que se me pide que haga el programa:

ejemplo

pero el problema es que no me guarda las notas que le ingreso ni el promedio y el momento de mostrar la información me muestra en 0.0 por favor necesito ayuda

el problema:
ejemplo2

Codigo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <conio.h>
#include <stdio.h>
 
struct fecha{
	int dia,mes,anio;
};
 
struct dataEstudiante{
	char nombre[10];
	char apellido[15];
	int edad;
	float notas[3];
	float promedio;
	struct fecha fechaNace;
};
dataEstudiante estu[3];
int numEstudiantes = 3;
int cantNotas = 3;
 
 
void ingresarDatos(int&x){
 
	printf("Por favor ingrese los datos del estudiante: %d \n\n",(x+1));
	printf("Nombre: \n");
	scanf("%s",estu[x].nombre);
	printf("Apellido: \n");
	scanf("%s",estu[x].apellido);
	printf("Edad: \n");
	scanf("%d",&estu[x].edad);
	printf("Ingresa la fecha de nacimiento del estudiante: \n");
	printf("Dia: \n");
	scanf("%d",&estu[x].fechaNace.dia);
	printf("Mes: \n");
	scanf("%d",&estu[x].fechaNace.mes);
	printf("Anio: \n");
	scanf("%d",&estu[x].fechaNace.anio);
 
	float valor = 0;
	for(int i=0; i < cantNotas; i++){
		printf("Por favor ingrese la nota: %d\n",(i+1));
		scanf("%f",&estu[x].notas[i]);
		valor += estu[x].notas[i];
	}
	estu[x].promedio = valor / cantNotas;
	fflush(stdin);
}
 
float promedioEdad(){
	float promedio;
	float acomular = 0;
	for(int i = 0; i< numEstudiantes;i++){
		acomular+= estu[i].edad;
	}
	promedio = acomular/numEstudiantes;
	return promedio;
}
 
void estudianteInfo(int&x){
	int cantidad = 3;
	printf("Informacion del estudiante: %d \n",(x+1));
	printf("Nombre: %s\n",estu[x].nombre);
	printf("Apellido: %s\n",estu[x].apellido);
	printf("edad: %d\n",estu[x].edad);
	printf("Fecha de nacimiento: \n");
	printf("Dia: %d\n",estu[x].fechaNace.dia);
	printf("Mes: %d\n",estu[x].fechaNace.mes);
	printf("Anio: %d \n",estu[x].fechaNace.anio);
 
	for(int i=0;i<cantidad;i++){
		printf("Nota %d : %.1f\n",(i+1),estu[x].notas[i]);
	}
	printf("El promedio: %.1f \n",estu[x].promedio);
 
}
 
void mejorPromedio(){
	float mayorPromedio = 0;
	int note = 0;
	for(int i=0;i<numEstudiantes;i++){
		if(estu[i].promedio > mayorPromedio){
			mayorPromedio = estu[i].promedio;
			note = i;
		}
   }
   estudianteInfo(note);
}
 
void peorPromedio(){
	float menorPromedio = 1000;
	int note = 0;
	for(int i=0;i<numEstudiantes;i++){
		if(estu[i].promedio > menorPromedio){
			menorPromedio = estu[i].promedio;
			note = i;
		}
   }
estudianteInfo(note);
}
 
void peorNota(){
	int note;
	float notaMini = 1000;
	for(int i=0;i<numEstudiantes;i++){
		if(estu[i].notas[0] < notaMini){
			notaMini = estu[i].notas[0];
			note = i;
		}
	}
	estudianteInfo(note);
}
 
void estudianteInfo(int&x);
void ingresarDatos(int&x);
float promedioEdad();
void mejorPromedio();
void peorPromedio();
void peorNota();
 
 
int main(){
 
 
	printf("----------------Bienvenido----------------\n");
	printf("-------------------Menu-------------------\n");
	printf("\n 1. Ingresar los datos\n");
	printf("\n 2. Calcular promedio de edades\n");
	printf("\n 3. Mostrar datos de los mayores de edad\n");
	printf("\n 4. Ver mejor promedio\n");
	printf("\n 5. Ver peor promedio\n");
	printf("\n 6. Ver la nota mas baja \n");
	printf("\n 0. SALIR\n");
 
	int opcion;
	scanf("%d",&opcion);
	switch(opcion){
		case 1:
			for(int i=0;i<numEstudiantes;i++){
				ingresarDatos(i);
			}
			main();
			break;
		case 2:
			printf("El promedio de edad es: %.1f\n",promedioEdad());
			main();
			break;
		case 3:
			printf("Los estudiantes mayores de edad: \n");
			for(int i=0;i<numEstudiantes;i++){
					if(estu[i].edad>= 18){
						estudianteInfo(i);
					}
				}
				main();
			break;
		case 4:
			printf("El promedio  mayor es: \n");
			mejorPromedio();
			main();
			break;
		case 5:
			printf("El promedio  menor es: \n");
			peorPromedio();
			main();
			break;
		case 6:
			printf("El estudiante que obtuvo la nota mas baja es:");
			peorNota();
			main();
			break;
		case 0:
 
			break;
		default:
			printf("Datos mal ingresados");
			break;
		}
	getch();
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder