Write a function to calculate the distance a vehicle has traveled for a given time period
at a given speed. The distance travelled can be calculated from the following formula:
distance = speed * time period
For example, if a car travels at 110 km per hour for three hours, the distance travelled
is 330 km.
#include <iostream>
using namespace std;
void distance(double time, double speed) {
cout << "The distance is: " << speed*time << "km" << '\n';
}
int main()
{
distance(3, 110);
return 0;
}
Output:
The distance is: 330 km
Comments
Leave a comment