fork download
  1. #include <stdio.h>
  2. int main()
  3. {
  4. float sum = 0; // sum of the employee hours, NOT using C99
  5.  
  6. for (int idx = 1; idx <5; ++idx) { // idx is a loop index, C99
  7. float hours; // hours worked in a given week, C99
  8.  
  9. printf("Enter Hours Worked:");
  10. scanf ("%f", &hours);
  11. sum += hours; // calculate sum of hours as a running total
  12. } // end for
  13.  
  14. printf ("\n Total sum of hours is %6.2f\n" , sum);
  15.  
  16. // if you try to reference the variables idx or hours here, you will get a syntax error
  17.  
  18. return (0);
  19.  
  20. } // end main
Success #stdin #stdout 0.01s 5320KB
stdin
35
stdout
Enter Hours Worked:Enter Hours Worked:Enter Hours Worked:Enter Hours Worked:
 Total sum of hours is 140.00