fork download
  1. // Running times calculator
  2.  
  3. # include <stdio.h>
  4. # include <math.h>
  5.  
  6. int main ()
  7. {
  8. float cTime;
  9. float gTime;
  10. float cDist;
  11. float gDist;
  12.  
  13. float min;
  14. float sec;
  15.  
  16. float cMin;
  17. float cSec;
  18. float p1000;
  19.  
  20. char response[1];
  21.  
  22. int blank;
  23.  
  24. printf ("Welcome to the running times calculator.\n\nEnter your completed race distance in metres: \n");
  25. scanf ("%f", &cDist);
  26. printf("Enter your completed race time. Type minutes, hit enter. Type seconds, hit enter\n");
  27. scanf ("%f" "%f", &cMin, &cSec);
  28.  
  29. cTime = cSec+(60*cMin);
  30. p1000 = pow(1000/cDist,1.1)*cTime;
  31.  
  32. printf ("Would you like to enter another race time to improve prediction accuracy? \n");
  33. scanf ("%s", &response);
  34.  
  35. if(response == "yes")
  36. {
  37. printf ("Enter your completed race distance in metres: \n");
  38. scanf ("%f", &cDist);
  39. printf("Enter your completed race time. Type minutes, hit enter. Type seconds, hit enter\n");
  40. scanf ("%f" "%f", &cMin, &cSec);
  41.  
  42. cTime = cSec+(60*cMin);
  43. p1000 = ((pow(1000/cDist,1.1)*cTime)+p1000)/2;
  44.  
  45. }
  46.  
  47. printf ("What is your goal race distance in metres? \n");
  48. scanf ("%f", &gDist);
  49.  
  50. gTime = pow(gDist/1000, 1.1)*p1000;
  51. min = gTime/60;
  52. sec = remainder(gTime,60);
  53.  
  54. if (sec < 0)
  55. {
  56. sec = sec + 60;
  57. min = min - 1;
  58. }
  59. printf ("Your predicted time for a race of %.0f metres is %.0f minutes and %.0f seconds", gDist, min, sec);
  60. scanf("%f", &blank);
  61.  
  62. return 0;
  63. }
Success #stdin #stdout 0s 1836KB
stdin
Standard input is empty
stdout
Welcome to the running times calculator.

Enter your completed race distance in metres: 
Enter your completed race time. Type minutes, hit enter. Type seconds, hit enter
Would you like to enter another race time to improve prediction accuracy? 
What is your goal race distance in metres? 
Your predicted time for a race of -0 metres is -nan minutes and -nan seconds