-
Notifications
You must be signed in to change notification settings - Fork 0
/
cs135_A2.cpp
37 lines (22 loc) · 1.14 KB
/
cs135_A2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//Captain-Price-TF-141
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int x, y, h, m; /*x is Car A, y is Car B, h is hours, m is minutes.*/
double time, minutes, distance, finaldistance; /*time is hours and minutes added, minutes is divided by 60, distance is the result of pythagorean theorem, finaldistance is the displayed distance.*/
cout << endl;
cout << "Enter the speed of Car A and Car B: ";
cin >> x >> y; /* Asks for the speed of Car A and Car B.*/
cout << "Enter elapsed time ( hours and minutes ): ";
cin >> h >> m; /* Asks for the Time in hours and minutes.*/
minutes = m / 60.0;
time = h + minutes; /*Adds the calculted hours and given minutes.*/
distance = pow((x * time), 2) + pow((y * time), 2); /*Performs pythagorean theorem to find the distnace, square root is used instead of squaring.*/
finaldistance = sqrt(distance); /*Square rooted distance above to get a final distance.*/
cout << "The two cars are " << finaldistance << " miles apart from each other" << endl; /* Displays the distance from the above calculation.*/
cout << endl;
return 0;
}