I'm trying to finish an exercise that asks for 4 ages, and the output tells how many of the entered ages are greater than or equal to 18 but the counter always adds a value greater than 18 at the end and I do not understand the 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);
}