fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. /* variable definition: */
  5. int 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 if !=)
  13. {
  14. printf("Enter a positive Integer\n");
  15.  
  16. scanf("%d", &value);
  17. if (value >= 0) {
  18. sum = sum + value;
  19. count = count + 1;
  20. }
  21. else {
  22. printf("Value must be positive\n");
  23. }
  24. }
  25. // Calculate avg. Need to type cast since two integers will yield an integer
  26. avg = (double) sum/count;
  27. printf("average is %lf\n " , avg );
  28. return 0;
  29. }
  30.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5

compilation info
prog.c: In function ‘main’:
prog.c:12:14: error: expected ‘)’ before ‘if’
 while (count if !=)
              ^~
stdout
Standard output is empty