【发布时间】:2019-11-15 01:24:38
【问题描述】:
C++ 中的摄氏温度表
C = 5/9 (F-32)
编写一个名为Celsius 的函数,它接受华氏温度作为参数。名为 Celsius 的函数,接受华氏温度作为参数。该函数应返回温度,转换为摄氏度。通过在循环中调用该函数来演示该函数,该循环显示华氏温度 0 到 20 及其等效摄氏温度表。
我知道我即将完成这个程序,但我似乎混淆/错过了我的变量。它应该打印出一个两列的表格,其中从 0-20 的临时转换每次增加 5。任何帮助都会很棒!这是我的代码:
#include <iostream>
#include <iomanip>
using namespace std;
// Create prototype
double celsius(double);
int main()
{
double cTemp;
for(int temp = 0; temp <= 20; temp+= 5)
{
double celTemp;
//Call the function
celTemp = celsius(temp);
cout << "The temperature in celsius is: " << temp << setw(6) <<
cTemp << endl;
}
}
double celsius(double farenheit)
{
double cTemp;
cTemp = 5.0 /9.0 * (farenheit - 32);
return cTemp;
}
【问题讨论】:
-
请描述您当前代码遇到的具体问题。
-
不要忘记
argv的存在,它比 1980 年代风格的“你想玩游戏吗?[Y/N]”类型提示要少得多。 -
现在有了更改的代码,为什么
main()中存在变量cTemp;?你从来没有给它一个值,但你尝试输出它。也许您想删除double cTemp;并输出celTemp。
标签: c++