The exercise asks me to read 20 students and their respective heights and sex, and then show the average height and how many men and women we have.
What I did was the following:
int main() {
float altura, media;
char gen, mediam, mediaf;
int contador;
contador = 0;
printf("Cálculo de alunos e alunas e média de suas alturas\n");
while (contador < 3) {
printf("Digite a altura e o sexo do aluno\n");
scanf("%f", &altura);
media = media + altura;
scanf("%s", &gen);
if (gen = 'm') {
mediam = mediam + gen;
} else {
mediaf = mediaf + gen;
}
contador++;
}
printf("A média de altura dos alunos é: \n%f", media);
printf("Temos %s alunos homens e %s alunos mulheres\n", mediam, mediaf);
return 0;
}+
I was able to make the program read the total height of the students, but when I enter the share of the male and female students, the line reading the heights itself gives a segmentation fault error.