fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. /* variable definition: */
  5. float count, value, sum;
  6. double avg;
  7. /* Initialize */
  8. count = 0;
  9. sum = 0;
  10. avg = 0.0;
  11. // Loop through to input values
  12. while (count < 10)
  13. {
  14. printf("Enter a positive Integer\n");
  15. scanf("%d", &value);
  16. if (value >= 0) {
  17. sum = sum + value;
  18. count = count + 1;
  19. }
  20. else {
  21. printf("Value must be positive\n");
  22. }
  23. }
  24. // Calculate avg. Need to type cast since two integers will yield an integer
  25. avg = (double) sum/count;
  26. printf("average is %lf\n " , avg )
  27. return 0;
  28. }
  29.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
1 2 3 4 5 6 7 8 9 0
compilation info
prog.c: In function ‘main’:
prog.c:15:10: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘float *’ [-Wformat=]
  scanf("%d", &value);
          ^
prog.c:27:2: error: expected ‘;’ before ‘return’
  return 0;
  ^~~~~~
stdout
Standard output is empty