Track laps to miles

One lap around a standard high-school running track is exactly 0.25 miles. Define a function named LapsToMiles that takes a double as a parameter, representing the number of laps, and returns a double that represents the number of miles. Then, write a main program that takes a number of laps as an input, calls function LapsToMiles() to calculate the number of miles, and outputs the number of miles.

Output each floating-point value with two digits after the decimal point, which can be achieved by executing
cout << fixed << setprecision(2); once before all other cout statements.

Ex: If the input is:

7.6
the output is:

1.90

-Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <iomanip>                 // For setprecision
using namespace std;

                                   / Defined function here / 
double LapsToMiles(double userLaps)
{
   double numLaps;
   return userLaps / 0.25;
}
                                    /Actual Code/
int main() {
   double userLaps;
   cin>>userLaps;
   cout<<fixed<<setprecision(2);
   cout<<LapsToMiles(userLaps);
  

   return 0;
}

It is currently outputting: 30.40
Last edited on
Check your arithmetic.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

Last edited on
Oh I see, It’s not the code that’s the problem, its the math.

I was supposed to do:

return userLaps / 4;

Thanks for your help!
Topic archived. No new replies allowed.