this is a follow up question of another one that I asked yesterday.
The goal of the code is to ask the user for the name of one student, 4 of their subjects and their respective grade of each subject.
The thing is: The program succesfully ask the user for the name, the first subject and the first respective grade. But when the program goes to ask for the second subject name, it shows the message asking the user for it, then ignores the 'gets' and immediatly shows the error message that no valid name was input, then shows the message asking the user again for the name, and this time let the user type in.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main(){
printf("Este programa captura el nombre de un alumno \n");
printf ("y cuatro de sus materias y sus respectivas notas\n");
printf ("Nota: El programa solo toma en cuenta los dos primeros\n");
printf ("decimales de la notas expresada.\n\n");
char alumno[40] = {'\0'};
char mat[4][20] = {'\0', '\0', '\0', '\0'};
float calif[4] = {-1.0, -1.0, -1.0, -1.0};
int i;
while (alumno[0] == '\0'){
printf("Ingresa el nombre del alumno: ");
gets(alumno);
if(alumno[0] == '\0'){
printf("\nError. El alumno debe de llevar un nombre.");
printf ("\nTrata nuevamente\n\n");
};
};
for(i = 0; i < 4; ++i){
while (mat[i][0] == '\0'){
printf("Ingresa el nombre de la materia %d: ", i+1);
gets(mat[i]);
if(mat[i][0] == '\0'){
printf("\nError. Las materias deben ser declaradas.");
printf ("\nTrata nuevamente.\n\n");
};
};
while (calif[i]<0 || calif[i]>10){
printf("Ingrese la nota correspondiente a esta materia (0-10): ");
scanf("%f", &calif[i]);
if(calif[i]<0 || calif[i]>10){
printf("\nError. Debe ingresar una nota entre 0 y 10.");
printf ("\nTrata nuevamente.\n\n");
};
};
};
return 0;
};
What's wrong with the code?