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