12345678910111213141516171819202122232425262728293031 |
- #include <iostream>
- #include <iomanip>
- int main() {
- double distance;
- double timeInput;
- int minutes, seconds, totalSeconds;
- double speedMps, speedKmph;
- std::cout << "Calculating running speed." << std::endl;
- std::cout << "Enter the length of distance (meters) = ";
- std::cin >> distance;
- std::cout << "Enter time (min.sec) = ";
- std::cin >> timeInput;
- minutes = static_cast<int>(timeInput);
- seconds = (timeInput - minutes) * 100;
- totalSeconds = minutes * 60 + static_cast<int>(seconds);
- speedMps = distance / totalSeconds;
- speedKmph = speedMps * 3.6;
- std::cout << "Distance: " << distance << " m" << std::endl;
- std::cout << "Time: " << minutes << " min " << static_cast<int>(seconds) << " sec = " << totalSeconds << " seconds" << std::endl;
- std::cout << "You were running at speed " << std::fixed << std::setprecision(2) << speedKmph << " km/h" << std::endl;
- return 0;
- }
|