Respuesta :
Answer:
The program to this question can be given as:
Program:
#include <iostream> //header file
using namespace std; //using namespace
double MphAndMinutesToMiles(double milesPerHour, double minutesTraveled) //defining method
{
return (minutesTraveled/ 60.0)*milesPerHour; //return value.
}
int main() //defining main method
{
double milesPerHour,minutesTraveled; //define variable
cout<<"Enter miles per hour :";
cin >> milesPerHour;
cout<<"Enter travelling minutes :";
cin >> minutesTraveled;
cout << "Miles: "<< MphAndMinutesToMiles(milesPerHour, minutesTraveled)<< endl;
return 0;
}
Output:
Enter miles per hour :12
Enter travelling minutes :20
Miles: 4
Explanation:
The explanation of the above C++ program can be given as:
- In the first header file is include the function is define that is "MphAndMinutesToMiles". This function accepts two parameters that are "milesPerHour and minutesTraveled".
- Both parameter datatype is double and the function return type is also double. Inside a function calculate miles and return its value.
- In the main method, two variable defines that takes value from the user side and pass into the function. To print function return value we use "cout" function that prints function return value.
The program illustrates the use of functions.
Functions are used to group similar set of instructions together in order to achieve a specific outcome.
The required function is as follows:
double MphAndMinutesToMiles(double milesPerHour, double minutesTraveled){
return milesPerHour * minutesTraveled/60;
}
The first line of the function declares the function, and its parameters.
double MphAndMinutesToMiles(double milesPerHour, double minutesTraveled)
- The function name is MphAndMinutesToMiles
- The function type is double
- The function parameters are milesPerHour and minutesTraveled
The second line of the function calculates the miles traveled, and returns it back to main().
return milesPerHour * minutesTraveled/60;
See attachment for complete program and the sample run
Read more about similar programs at:
https://brainly.com/question/9380688
