0
the code below is intended to read a Qtd amount of people in a family, receive the sum of ages and present the average at the end:
#include <stdio.h>
int main()
{
int qtd, idade, i;
float soma=0 , media;
printf("Informe quantos membros há na família: ");
scanf("%d\n", qtd);
do{
printf("informe a idade: ");
scanf("%d\n", idade);
soma += idade;
i++;
}while(i<= qtd);
media = soma / qtd;
printf("a média de idade da família é: %f\n",media);
return 0;
}
It occurs Segmentation fault (sometimes followed by core dump) so it makes the literacy of qtd
not intending what access violation I committed in the above code.
where is the "i" boot? but the error is here: "scanf("%d n", Qtd);" --> scanf("%d n", &Qtd);"
– zentrunix
When you want to read a scalar value, the arguments after the format string should be pointers
– Jefferson Quesado
@zentrunix the initialization of the variable in the global scope gave no difference (i=0). In fact, I forgot the '&' but still, after reading the Qtd it waits for the input of something else and only then enters the while loop. Finally it either generates an incorrect value or... Segmentation fault.
– wes85melis
and where is the "&" in the "age" scanf" ?
– zentrunix