Respuesta :
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
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.
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))
Explanation: