214k views
3 votes
5.23 LAB: Miles to track laps

One lap around a standard high-school running track is exactly 0.25 miles. Write a program that takes a number of miles as input, and outputs the number of laps.


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:


1.5

the output is:


6.00

Ex: If the input is:


2.2

the output is:


8.80

Your program must define and call a function:

double MilesToLaps(double userMiles)

has to be done in c++

2 Answers

6 votes

Answer:

def miles_to_laps(miles):

return miles / 0.25

miles = 5.2

num_of_lap = miles_to_laps(miles)

print("%0.2f miles is %0.2f lap(s)" % (miles, num_of_lap))

Step-by-step explanation:

User Nurdyguy
by
4.8k points
5 votes

Answer:

Following are the code to this question:

#include <iostream>//defining header file

#include <iomanip> //defining header file

using namespace std;

double MilesToLaps(double userMiles)//defining method MilesToLaps which accepts parameter

{

double numlaps; //defining double variable

numlaps = userMiles / 0.25; //calculating and holding numlaps value

return numlaps; //return value

}

int main() //defining main method

{

double userMiles;//defining double variable userMiles

cout<<"Enter miles value: ";//print message

cin>>userMiles;//input value

cout<<fixed<<setprecision(2);//using setprecision method

cout<<"Total laps: "<<MilesToLaps(userMiles);//print MilesToLaps method value

return 0;

}

Output:

Enter miles value: 1.5

Total laps: 6.00

Step-by-step explanation:

Description of the above code:

  • In the above program, a double method "MilesToLaps" is declared, which accepts "userMiles" a double variable in its parameter. Inside the method, a double variable "numlaps" is declared, which divides the "userMiles" value by 0.25 and returns its value.
  • In the main method, a double variable "userMiles" is declared that inputs value from the user end and use the setprecision and call the method "MilesToLaps" and prints its return value.
User AeroBuffalo
by
5.1k points