In: Computer Science
Your car travels west at an average speed of x kilometers per hour and your friend’s car travels south at an average speed of Y Kilometers per hour. Write a C++ code that prompts the user to enter the average speed of your car and your friend’s car and the elapsed time in hours and minutes since the 2 cars started their movement, and output the shortest distance between the 2 cars.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x,y,hours,minutes;
cout<<"Enter the average speed of your car(KMPH): ";
cin>>x;
cout<<"Enter the average speed of your friend’s car(KMPH):
";
cin>>y;
cout<<"Enter the elapsed time in hours and minutes since the
2 cars started their movement: ";
cin>>hours;
cin>>minutes;
double xD=x*(hours+minutes/60.0);
double yD=y*(hours+minutes/60.0);
cout<<"Shortest distance =
"<<(sqrt(xD*xD+yD*yD));
return 0;
}