Write a program that will input miles traveled and hours spent in travel. The pr
ID: 3625623 • Letter: W
Question
Write a program that will input miles traveled and hours spent intravel. The program will determine miles per hour. This calculation must
be done in a function other than main; however, main will print the
calculation. The function will thus have 3 parameters: miles, hours, and
milesPerHour. Which parameter(s) are pass by value and which are
passed by reference? Output is fixed with 2 decimal point precision.
Sample Run:
Please input the miles traveled
475
Please input the hours traveled
8
Your speed is 59.38 miles per hour
Explanation / Answer
//CPP program for calculate miles per hour
#include<iostream>
using namespace std;
void calculation(double,double,double);
int main()
{
double miles,hours,mph;
cout<<"Please input the miles traveled";
cin>>miles;
cout<<"Please input the hours traveled";
cin>>hours;
calculation(miles,hours,mph);
system("pause");
}
void calculation(double m,double h,double mh)
{
double mph = (m/h);
cout<<"You speed is " <<mph<<"miles per hour";
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.