-3
I have to read 6 values and then show how many of these typed values were positive. On the next line, you should show the average of all positive values typed, with one digit after the decimal point.
The code is meeting all the requirements of the question, however it is not returning the average of all positive values typed and I’m not understanding the reason.
Code:
#include <stdio.h>
int main() {
int counterNumPositivos, soma, counterEntradas;
double numDigitado, media;
soma = 0;
counterNumPositivos = 0;
counterEntradas = 0;
while (counterEntradas <6){
scanf("%lf", &numDigitado);
counterEntradas += 1;
soma += numDigitado;
if (numDigitado >= 0)
counterNumPositivos += 1;
}
media = soma / 6;
printf("%d valores positivos\n", counterNumPositivos);
printf("%.1f\n", media);
return 0;
}
I’m racking my brain with something that I believe is simple haha.
Corrected here. Thanks for the remark!
– Natan Fernandes
If I’ve solved your question, don’t forget to mark it as a response in the green tick. This makes more people with the same doubt that you can easily find the solution to the problem.
– Natan Fernandes