fork download
  1. //Developer: Branden J. Randall
  2. //Date: June 24, 2017
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7. /* variable definition: */
  8. int lap;
  9. float time, avg, total;
  10. /* Initialize */
  11. lap = 0;
  12. total = 0;
  13. avg = 0.0;
  14.  
  15. // Initial Value
  16.  
  17. printf("Enter a lap time or 999 to terminate.");
  18. scanf("%f", &time);
  19.  
  20. // Loop Starts Here
  21. while (time != 999)
  22. {
  23. total = total + time;
  24. lap = lap + 1;
  25.  
  26. printf("Total = %f Lap = %d\n", total, lap);
  27.  
  28. printf("Enter a lap time or 999 to terminate.");
  29. scanf("%f", &time);
  30.  
  31. }
  32. //Computing the average
  33.  
  34. avg = (float)total/lap;
  35. printf("The average lap time is %.2f\n", avg);
  36. return 0;
  37. }
  38.  
  39.  
Success #stdin #stdout 0s 9432KB
stdin
94.4
99.99
101.741
999
stdout
Enter a lap time or 999 to terminate.Total = 94.400002 Lap = 1
Enter a lap time or 999 to terminate.Total = 194.389999 Lap = 2
Enter a lap time or 999 to terminate.Total = 296.130981 Lap = 3
Enter a lap time or 999 to terminate.The average lap time is 98.71