0
I’m trying to finish an exercise that asks for 4 ages and the output tells how many of the inserted ages are greater than or equal to 18 but the counter always adds a value greater than 18 at the end and I don’t understand why.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int vetor[3], *pvetor = &vetor[0],i,cont=0;
for(i=0;i<4;i++)
{
printf("Introduza a %d idade: ",i+1);
scanf("%d",&vetor[i]);
}
while(*pvetor != NULL)
{
if(*pvetor >= 18)
cont++;
pvetor++;
}
printf("Das %d idades inseridas, %d sao maiores de idade.",4,cont);
}
This code does not seem to do what is described, the error is in the code or in the description?
– Maniero
I was wrong in the description the purpose is to tell how many ages are greater than or equal to 18*
– user117670
No, this is written in the description. Without knowing what the problem is, there is no way to know what the solution is.
– Maniero
I’ve corrected the description
– user117670