Dev - C++ - alguien me ayuda con este codigo? en la parte de int esNumero estoy mal

 
Vista:

alguien me ayuda con este codigo? en la parte de int esNumero estoy mal

Publicado por ismael (1 intervención) el 27/03/2022 06:56:52
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N_MATERIAS 5
#define N_ALUMNOS 5

typedef struct _Alumno{
char Nombre[40];
float Notas[N_MATERIAS];
float Promedio;
}ALUMNO;

char Materias[N_MATERIAS][40];

int RegistrarEstudiantes(ALUMNO a[]);
int RegistrarClases();

int main (){
ALUMNO Estudiante[N_ALUMNOS];

RegistrarClases();

RegistrarEstudiantes(Estudiante);

int i = 0;
while(i < N_MATERIAS){
printf("Nombre : %s\n",Materias[i]);
i++;
}
return 0;
}

int RegistrarClases(){
int i = 0;
int Result = 0;
printf("\t\tREGISTRE MATERIAS\n");
while(i < N_MATERIAS){
printf("MATERIA (%d) : ", (i+1)); fflush(stdin);
Result = scanf("%[^\n]",Materias[i]);
if((Result == EOF) || (ferror(stdin))){
return 0;
}
i++;
}
return 1;
}

int RegistrarEstudiantes(ALUMNO a[]){
int i = 0 , j;
int Result = 0;
char buffer[30];
float suma;

while(i < N_ALUMNOS){
system("cls");
printf("\t\tREGISTRO DE ESTUDIANTES\n\n");
printf("NOMBRE Y APELLIDO : "); fflush(stdin);
Result = scanf("%[^\n]",a[i].Nombre);

if( (Result == EOF) || (ferror(stdin)) ){
return 0;
}
suma = 0;
printf("\t\tREGISTRE NOTAS:\n");
for(j = 0; j < N_MATERIAS; j++){
do{

do{

printf("%s : ",Materias[j]); fflush(stdin);
Result = scanf("%[^\n]",buffer);
if( (Result == EOF) || (ferror(stdin)) ){
return 0;
}
}while(!esNumero(buffer));
errno = 0;
a[i].Notas[j] = (float)strtod(buffer,NULL);
if(error != 0){
return 0;
}
}while( (a[i].Notas[j] > 10) || (a[i].Notas[j] < 0));

suma += a[i].Notas[j];
}
a[i].Promedio = suma/N_MATERIAS;
i++;
}
return 1;

}

int esNumero(const char* buffer){
if((buffer == NULL) || (buffer[0] == '\0') || (strcmp(buffer,"-") == 0) || (strcmp(buffer,"-") == 0 ){

return 0;
}
int i = 0,nPuntos = 0;
while(buffer[i] != '\0'){
if(buffer[i] == '.'){
if(++nPuntos > 1){
return 0;
}

}
if( !(isdigit(buffer[i]) || buffer[i] == '.' || ((buffer[i] == '-') && (i = 0) ) ) ){
return 0;
}
i++;
}
return 1;
}
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
Imágen de perfil de Alfil
Val: 4.344
Oro
Ha mantenido su posición en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

alguien me ayuda con este codigo? en la parte de int esNumero estoy mal

Publicado por Alfil (1444 intervenciones) el 27/03/2022 11:14:10
Me he limitado a hacer andar el programa.


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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
 
#define N_MATERIAS 5
#define N_ALUMNOS 5
 
typedef struct _Alumno{
    char Nombre[40];
    float Notas[N_MATERIAS];
    float Promedio;
}ALUMNO;
 
char Materias[N_MATERIAS][40];
 
int RegistrarEstudiantes(ALUMNO a[]);
int RegistrarClases();
int esNumero(const char* buffer);
 
int main ()
{
    ALUMNO Estudiante[N_ALUMNOS];
 
    RegistrarClases();
    RegistrarEstudiantes(Estudiante);
 
    int i = 0;
    while(i < N_MATERIAS)
    {
        printf("Nombre : %s\n",Materias[i]);
        i++;
    }
    return 0;
}
 
int RegistrarClases()
{
    int i = 0;
    int Result = 0;
    printf("\t\tREGISTRE MATERIAS\n");
    while(i < N_MATERIAS)
    {
        printf("MATERIA (%d) : ", (i+1)); fflush(stdin);
        Result = scanf("%[^\n]",Materias[i]);
        if((Result == EOF) || (ferror(stdin)))
        {
            return 0;
        }
        i++;
    }
    return 1;
}
 
int RegistrarEstudiantes(ALUMNO a[])
{
    int i = 0 , j;
    int Result = 0;
    char buffer[30];
    float suma;
 
    while(i < N_ALUMNOS)
    {
        system("cls");
        printf("\t\tREGISTRO DE ESTUDIANTES\n\n");
        printf("NOMBRE Y APELLIDO : "); fflush(stdin);
        Result = scanf("%[^\n]",a[i].Nombre);
 
        if( (Result == EOF) || (ferror(stdin)) )
        {
            return 0;
        }
        suma = 0;
        printf("\t\tREGISTRE NOTAS:\n");
        for(j = 0; j < N_MATERIAS; j++)
        {
            do{
 
                do{
 
                    printf("%s : ",Materias[j]); fflush(stdin);
                    Result = scanf("%[^\n]",buffer);
                    if( (Result == EOF) || (ferror(stdin)) )
                    {
                        return 0;
                    }
                }while(!esNumero(buffer));
                errno = 0;
                a[i].Notas[j] = (float)strtod(buffer,NULL);
                if(errno != 0)
                {
                    return 0;
                }
            }while( (a[i].Notas[j] > 10) || (a[i].Notas[j] < 0));
 
            suma += a[i].Notas[j];
        }
        a[i].Promedio = suma/N_MATERIAS;
        i++;
    }
    return 1;
 
}
 
int esNumero(const char* buffer)
{
    if((buffer == NULL) || (buffer[0] == '\0') || (strcmp(buffer,"-") == 0) || (strcmp(buffer,"-") == 0 ))
    {
        return 0;
    }
    int i = 0,nPuntos = 0;
    while(buffer[i] != '\0')
    {
        if(buffer[i] == '.')
        {
            if(++nPuntos > 1)
            {
                return 0;
            }
        }
        if( !(isdigit(buffer[i]) || buffer[i] == '.' || ((buffer[i] == '-') && (i = 0) ) ) )
        {
            return 0;
        }
        i++;
    }
    return 1;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar