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;
}
全部评论

相关推荐

头像
11-09 12:17
清华大学 C++
out11Man:小丑罢了,不用理会
点赞 评论 收藏
分享
预计下个星期就能开奖吧,哪位老哥来给个准信
华孝子爱信等:对接人上周说的是这周
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务