A man walks 7 km in 2 hours and 2 km in 1 hour in the same direction.a) What is the man's average speed for the whole journey?Create a program that will automatically compute for the man’s average speed. Use function in designing the program. The formula on how to get the speed is speed = distance / time
#include <iostream>
using namespace std;
float calculateSpeed(float distance,float time){
float speed = distance / time;
return speed;
}
int main() {
float averageSpeed=(calculateSpeed(7.0,2.0)+calculateSpeed(2.0,1.0))/2.0;
cout<<"The man's average speed for the whole journey: "<<averageSpeed<<" km/hour\n\n";
cin>>averageSpeed;
return 0;
}
Comments
Leave a comment