task1.6.cpp 948 B

12345678910111213141516171819202122232425262728293031
  1. #include <iostream>
  2. #include <iomanip>
  3. int main() {
  4. double distance;
  5. double timeInput;
  6. int minutes, seconds, totalSeconds;
  7. double speedMps, speedKmph;
  8. std::cout << "Calculating running speed." << std::endl;
  9. std::cout << "Enter the length of distance (meters) = ";
  10. std::cin >> distance;
  11. std::cout << "Enter time (min.sec) = ";
  12. std::cin >> timeInput;
  13. minutes = static_cast<int>(timeInput);
  14. seconds = (timeInput - minutes) * 100;
  15. totalSeconds = minutes * 60 + static_cast<int>(seconds);
  16. speedMps = distance / totalSeconds;
  17. speedKmph = speedMps * 3.6;
  18. std::cout << "Distance: " << distance << " m" << std::endl;
  19. std::cout << "Time: " << minutes << " min " << static_cast<int>(seconds) << " sec = " << totalSeconds << " seconds" << std::endl;
  20. std::cout << "You were running at speed " << std::fixed << std::setprecision(2) << speedKmph << " km/h" << std::endl;
  21. return 0;
  22. }