Advertisement
Guest User

yesz

a guest
Apr 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. /*
  2. *
  3. * Reid Luttrell - CS-161-0-20509
  4. * This is a simple program to take info of cars and output the shortest distance between them
  5. *
  6. */
  7.  
  8. #include <iostream>
  9. #include <cmath>
  10.  
  11. using namespace std;
  12.  
  13. #define MINUTES_PER_HOUR 60
  14.  
  15. int main() {
  16. // initialize values needed
  17. int iCarASpeed;
  18. int iCarBSpeed;
  19. double dElapsedHours;
  20. double dElapsedMinutes;
  21.  
  22. // take input and store into initialized values
  23. cout << "Input the speed of Car A: ";
  24. cin >> iCarASpeed;
  25.  
  26. cout << "Input the speed of Car B: ";
  27. cin >> iCarBSpeed;
  28.  
  29. cout << "Input the elapsed time as hours and minutes seperated by a space: ";
  30. cin >> dElapsedHours >> dElapsedMinutes;
  31.  
  32. // calculate total amount of hours
  33. double dTotalHours = dElapsedHours + dElapsedMinutes / MINUTES_PER_HOUR;
  34.  
  35. // calculate distance
  36. double dDistance = sqrt(pow(iCarASpeed * dTotalHours, 2) + pow(iCarBSpeed * dTotalHours, 2));
  37.  
  38. // output
  39. cout << "\nShortest Distance: " << dDistance << endl;
  40.  
  41. // pause to see output
  42. system("PAUSE");
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement