I need to do a program that asks for the sex and age of a number of people (it is supposed to end by putting 'n' in sex) ... and then says how many women and men attended ... in addition to intervals of age (how many men and women of certain ages were registered) ... The point is that after the first iteration the program asks the sex ... then the age ... but immediately afterwards it asks again the age without going through the sex ... and I can not get out of there unless I force the exit or enter 'n' many times ...
/* Se supone que ingrese el sexo (F/f/M/m) y la edad de cada persona y cuando se
ingrese 'N' o 'n' en sexo...el programa debe indicar cuantas mujeres
fueron registradas y cuantas de ellas tenían entre 22 y 25 años...
en el caso de los hombres también se debe indicar cuantos se registraron
y decir cuántos de elos tenían entre 18 y 30 años...*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int edad, nvar=0, ndam=0, nv1830=0, nd2225=0;
char sexo;
do
{
printf("Ingrese sexo (F/M)(0 si no hay nadie): ");
scanf("%c", &sexo);
printf("\nIngrese edad (0 si no hay nadie): ");
scanf("%d", &edad);
if(sexo=='f' || sexo=='F')
{
ndam++;
if(edad>=22 && edad<=25)
{
nd2225++;
}
}
else if(sexo=='m' || sexo=='M')
{
nvar++;
if(edad>= 18 && edad<=30)
{
nv1830++;
}
}
else if(sexo=='n' || sexo=='N')
{
printf("Asistieron %d damas a la fiesta.\n", ndam);
printf("Damas con edades entre 22 y 25: %d\n", nd2225);
printf("\nAsistieron %d varones a la fiesta.\n", nvar);
printf("Varones con edades entre 18 y 30: %d\n", nv1830);
}
}
while(sexo!='n' || sexo!= 'N');
return 0;
}