我知道我即将完成该程序,但是我似乎混淆/遗漏了我的变量。它应该打印出一个两列的表格,其中温度转换从0到20每次增加5。任何帮助将是巨大的!这是我的代码:
#include <iostream>
#include <iomanip>
using namespace std;
// Create prototype
double celsius(double);
int main()
{
double cTemp;
cout << "Enter temperature to be converted to celsius: ";
cin >> 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;
}
您的
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;
}
不转换从输入读取的值。从您所说的还不清楚程序应该做什么,但是也许调用celsius()函数的参数不应该只是temp,而应该是(temp + cTemp)之类的东西。
for循环也忽略了从celsius()函数返回的值,并且总是在第二列中打印值cTemp(即从stdin读取的值),这也许是另一个错误。