You can compare the values of the elements of the structures by accessing the notation estructura.elemento
or in the case that the structure is referenced with a pointer with estructura->elemento
.
As an example if the structure and arrangement or vector are as follows:
struct persona{
int sexo;
int edad;
int estado;
};
struct persona lista[15];
You can scan the list as follows:
// variables para almacenar los resultados
int hombressolteros = 0;
int hombrescasados = 0;
int mujeressolteras = 0;
int mujerescasadas = 0;
int totalsolteros = 0;
int totalcasados = 0;
int menoresedad = 0;
for (int i = 0; i < 15; i++) {
// Comprobar si es mayor de edad
if (lista[i].edad < 18) {
menoresedad++;
}
// Comprobar si es hombre
else if (lista[i].sexo == 1) {
// Determinar si esta casado
if (lista[i].estado == 1) {
hombrescasados++;
}
else {
hombressolteros++;
}
}
// si es mujer
else {
// Determinar si es casada
if (lista[i].estado == 1) {
mujerescasadas++;
}
else {
mujeressolteras++;
}
}
}
// Totales
totalcasados = hombrescasados + mujerescasadas;
totalsolteros = hombressolteros + mujeressolteras;