fork download
  1.  
  2.  
  3. #include <stdio.h>
  4. int main ()
  5. {
  6. float sum = 0; /* sum of the employee hours */
  7.  
  8. for (int idx = 1; idx < 5; ++idx) {
  9. float hours; /* hours worked in a given week */
  10.  
  11. printf("Enter Hours Worked: ");
  12. scanf ("%f", &hours);
  13. sum += hours; /* calculate sum of hours */
  14. } /* end for */
  15.  
  16. printf ("\n Total sum of hours is %6.2f \n", sum);
  17.  
  18. /* if you try to reference the variables idx or hours here, you'll get an error */
  19.  
  20. return (0);
  21.  
  22. } /* end main */
  23.  
Success #stdin #stdout 0.01s 5276KB
stdin
100
56.5
74.3
67.45
40.0
stdout
Enter Hours Worked: Enter Hours Worked: Enter Hours Worked: Enter Hours Worked: 
 Total sum of hours is 298.25