Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original main():
int main() {
double milesPerHour;
double minutesTraveled;
double hoursTraveled;
double milesTraveled;
cin >> milesPerHour;
cin >> minutesTraveled;
hoursTraveled = minutesTraveled / 60.0;
milesTraveled = hoursTraveled * milesPerHour;
cout << "Miles: " << milesTraveled << endl;
return 0;
}
#include <iostream>
using namespace std;
void MphAndMinutesToMiles(double milesPerHour, double minutesTraveled)
{
cout << "Miles: " << (minutesTraveled / 60.0)*milesPerHour;
}
void main()
{
double milesPerHour;
double minutesTraveled;
cout << "Please, enter milesPerHour and minutesTraveled: ";
cin >> milesPerHour >> minutesTraveled;
MphAndMinutesToMiles(milesPerHour, minutesTraveled);
}
Comments
Leave a comment