C++程序设计:1.10

#include <iostream>
using namespace std;
int main()
{
    // Declare variables
    double distance_km = 14; // Distance in kilometers
    double distance_mile; // Distance in miles
    double time_min = 45; // Time in minutes
    double time_sec = 30; // Time in seconds
    double time_hour; // Time in hours
    double speed_mph; // Speed in miles per hour

    // Convert distance from kilometers to miles
    distance_mile = distance_km / 1.6;

    // Convert time from minutes and seconds to hours
    time_hour = (time_min + time_sec / 60) / 60;

    // Calculate speed by dividing distance by time
    speed_mph = distance_mile / time_hour;

    // Display the result
    cout << "The average speed is " << speed_mph << " miles per hour." << endl;

    return 0;
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务