Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * Reid Luttrell - CS-161-0-20509
- * This is a simple program to take info of cars and output the shortest distance between them
- *
- */
- #include <iostream>
- #include <cmath>
- using namespace std;
- #define MINUTES_PER_HOUR 60
- int main() {
- // initialize values needed
- int iCarASpeed;
- int iCarBSpeed;
- double dElapsedHours;
- double dElapsedMinutes;
- // take input and store into initialized values
- cout << "Input the speed of Car A: ";
- cin >> iCarASpeed;
- cout << "Input the speed of Car B: ";
- cin >> iCarBSpeed;
- cout << "Input the elapsed time as hours and minutes seperated by a space: ";
- cin >> dElapsedHours >> dElapsedMinutes;
- // calculate total amount of hours
- double dTotalHours = dElapsedHours + dElapsedMinutes / MINUTES_PER_HOUR;
- // calculate distance
- double dDistance = sqrt(pow(iCarASpeed * dTotalHours, 2) + pow(iCarBSpeed * dTotalHours, 2));
- // output
- cout << "\nShortest Distance: " << dDistance << endl;
- // pause to see output
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement