Menu
CoddyTech

基本输出

Coddy 使用 C++ 制作温度转换器 课程的第 8 课,共 10 课。

现在,我们已经有了所有转换函数!让我们创建用户界面(主函数),这样这个程序的用户就能轻松使用温度转换器。

challenge icon

挑战

简单

在代码中添加主函数(放在所有转换函数的下面)。在函数中,打印以下内容:

Temperature Converter
1. Celsius to Fahrenheit
2. Celsius to Kelvin
3. Fahrenheit to Celsius
4. Fahrenheit to Kelvin
5. Kelvin to Celsius
6. Kelvin to Fahrenheit

亲手试试

float celsiusToFahrenheit(float celsius) {
    return (celsius * 9.0 / 5.0) + 32.0;
}

double celsiusToKelvin(double celsius) {
    return celsius + 273.15;
}

double fahrenheitToCelsius(double fahrenheit) {
    return (fahrenheit - 32.0) * 5.0 / 9.0;
}

double fahrenheitToKelvin(double fahrenheit) {
    return (fahrenheit + 459.67) * 5.0 / 9.0;
}

double kelvinToCelsius(double kelvin) {
    return kelvin - 273.15;
}

double kelvinToFahrenheit(double kelvin) {
    return kelvin * 9.0 / 5.0 - 459.67;
}

使用 C++ 制作温度转换器中的所有课

自己练习: C++ 在线编译器