1
The exercise asks me to read 20 students and their respective heights and gender, and then show the average height and how many men and women we have.
What I did was this:
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 get the program to read the total height of the students, but when I type in the share of the total male and female students, the very line of reading the heights gives a mistake of Segmentation fault.
Is this the same statement? The code does not do what it is asking and does what it is not.
– Maniero
Yes, I managed to get the code to read the height. But maybe I didn’t use the right logic to read the number of men and women.
– steeph
The statement does not ask for this.
– Maniero
Sorry, the statement asks the average height and how many men and women have. I did not realize that I wrote wrong.
– steeph