fork(1) download
  1. // C code
  2. // This program will sum the distance run or walked in a week
  3. //Developer: Benjamin W. Swanson CMIS102
  4. // Date: Feb 09, 2018
  5. #include <stdio.h>
  6. int main ()
  7. {
  8. /* variable definition: */
  9. int days;
  10. float distance, total;
  11. /* Initialize */
  12. days = 0;
  13. total = 0;
  14. // Loop through to input values
  15. while (days < 7) {
  16. printf("how many miles did you walk/run today?\n");
  17. scanf("%f", &distance);
  18. if (distance > 0)
  19. {
  20. total = total + distance;
  21. days = days + 1;
  22. }else {
  23.  
  24. }
  25. }
  26. printf(" \nthis week you traveled %1f miles\n " , total );
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 4256KB
stdin
1
2
1
3
1
2
1
stdout
how many miles did you walk/run today?
how many miles did you walk/run today?
how many miles did you walk/run today?
how many miles did you walk/run today?
how many miles did you walk/run today?
how many miles did you walk/run today?
how many miles did you walk/run today?
 
this week you traveled 11.000000 miles