下面是将英寸转换为厘米的C++代码:

#include <iostream>

double inchesToCm(double inches) {
    const double cmPerInch = 2.54;
    return inches * cmPerInch;
}

int main() {
    double inches;
    std::cout << "请输入英寸数:";
    std::cin >> inches;

    double cm = inchesToCm(inches);
    std::cout << inches << " 英寸 = " << cm << " 厘米" << std::endl;

    return 0;
}

在上述代码中,inchesToCm函数将英寸数作为参数,并返回转换后的厘米数。main函数中,首先要求用户输入英寸数,然后调用inchesToCm函数进行转换,并输出结果。

qt C++ 将英寸转为cm

原文地址: https://www.cveoy.top/t/topic/hQMg 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录