I need to create a program in which the data of the students can be loaded, take the average of all the grades and show on the screen the data of the users with a grade higher than 7.
I understand that the problem is that I cannot match a char *
with a int
, however I cannot find the solution, since if I change to note by char
I can no longer create the if (alumno.nota >= 7)
.
Unless with some library I can convert the int to a char before the passage I can't think of another solution.
#include <iostream>
#include <conio.h>
#include <cstring>
#include <stdio.h>
/*Se leen datos de notas obtenidas por los alumnos de una cátedra y se
desea informar
− el promedio de las notas obtenidas por los alumnos
− el nombre, tipo y número de documento y número de legajo
(padrón) de los alumnos que hayan aprobado con nota igual o mayor
que siete.
− Los datos del/los alumnos con peor nota.
La secuencia finaliza con el alumno Wolf Roberto que debe ser
procesado*/
using namespace std;
struct notas
{
char nombre[50];
char tipodoc[50];
int DNI;
int Legajo;
int nota;
char aprobo[30];
};
void estructura_notas(float &promnota, char *mejoresalumnos[][4][50], int &cantalum)
{
int i=0;
int peornota;
notas alumno;
do
{
setlocale(LC_ALL, "spanish");
cout << "Ingrese el nombre: ";
fflush(stdin);
gets(alumno.nombre);
cout << "Ingrese el tipo de DOC: ";
fflush(stdin);
gets (alumno.tipodoc);
cout << "Ingrese el numero de DNI: ";
cin >> alumno.DNI;
cout << "Ingrese el legajo: ";
cin >> alumno.Legajo;
cout << "Ingrese la nota: ";
cin >> alumno.nota;
promnota = alumno.nota+promnota;
cout << "Ingrese si aprobo: ";
fflush(stdin);
gets (alumno.aprobo);
if (alumno.nota >= 7)
{
mejoresalumnos[i][0][50] = alumno.nombre;
mejoresalumnos[i][1][50] = alumno.tipodoc;
mejoresalumnos[i][2] = alumno.DNI;
mejoresalumnos[i][3] = alumno.Legajo;
mejoresalumnos[i][4] = alumno.nota;
i++;
}
}while(strcmp(alumno.nombre,"Wolf Roman"));
cantalum = i;
return;
}
int main()
{
setlocale(LC_ALL, "spanish");
char *mejoresalumnos[][4][50];
float promnota;
int cantalum;
notas alumno;
estructura_notas(promnota, mejoresalumnos, cantalum);
cout << "El promedio de todas las notas es: " << promnota/2 << endl;
for (int i; i<=cantalum; i++)
{
cout << "\n NOMBRE " << "||" << " TIPODOC " << "||" << " DNI " << "||" << " LEGAJO " << "||" << " NOTA " << endl;
cout << mejoresalumnos[i][0] << "||" << mejoresalumnos[i][1] << "||" << mejoresalumnos[i][2] << "||" << mejoresalumnos[i][3];
}
return 0;
}
You had many errors, of course there are ways to convert from
int
tochar
.But in your case, what you were doing was not the best execution to solve the problem, if what you have is a
struct
with defined data types, why not use the same typestruct
to return users with an average of less than 7?There I put a maximum of 20 students with the worst grade, but if you want it to be dynamic I recommend using malloc first and then realloc if you want to modify the sizeof.
And keep in mind that the group average is calculated with the total sum of all the grades divided by the number of students.
I also recommend that you review pointers .