Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am having a hard time with recursion, I have tried working on this and I feel

ID: 3588368 • Letter: I

Question

I am having a hard time with recursion, I have tried working on this and I feel lost. C++ Recursion Problem

I have determined that if I run 5 minutes, I can travel 0.67 miles the first 5 minutes. For every 5 minutes afterwards I run 0.05 less miles. So every 5 minutes I cover less distance. Now I want to know I far will I have run in 5 min, 10, 15, 20, 25, 30, 35, 40, 45, 50 mins. Print out the minutes of running and the distance I have covered. Print out in a table format with headings and the answers in two columns. Print the miles covered with 2 decimal digits of accuracy (2 decimal places to the right of decimal point.
NO LOOPS ALLOWED

1.      Example output format:

                  Minutes           Miles Traversed         


                 5          .67
            10         1.29
                        …..

Explanation / Answer

Given below is the recursive code without using loops. Hope it helps. If it did, please don't forget to rate the answer. Thank you.


#include <iostream>
using namespace std;
double milesRun(int minutes)
{
double miles ;
if(minutes <= 5) //base case for 5 or less minutes
miles = 0.67;
else //more than 5 mins
{
//less 0.05, and then use recursion to find the miles for other minutes after subtracting 5 mins
miles = (0.67 - 0.05) + milesRun(minutes - 5) ; //reduce 5 min
}
  
cout << minutes << " " << miles << endl;
return miles;
}

int main()
{
  
cout << "Minutes Miles" << endl;
milesRun(50);
}

output


Minutes Miles
5 0.67
10 1.29
15 1.91
20 2.53
25 3.15
30 3.77
35 4.39
40 5.01
45 5.63
50 6.25
Program ended with exit code: 0