【发布时间】:2020-02-08 22:49:48
【问题描述】:
我正在为班级工作,但我一直无法获得正确的输出。
#include<iostream>
using namespace std;
double celsiusToFahrenheit (double);
double fahrenheitToCelsius (double);
int main ()
{
double f;
double c;
cout.setf (ios::fixed);
cout.precision (2);
cout << "Celsius \t" << "Fahrenheit \t" << "| \t" << "Fahrenheit \t" << "Celsius" << endl;
cout << fahrenheitToCelsius (c) << "\t\t" << celsiusToFahrenheit (c) <<
endl;
return 0;
}
double celsiusToFahrenheit (double f)
{
double fahrenheit;
for (double celsius = 40.0; celsius >= 31.0; celsius--)
{
fahrenheit = (9.0 / 5.0) * celsius + 32.0;
cout << celsius << "\t\t" << fahrenheit << "\t\t|" << endl;
}
return fahrenheit;
}
double fahrenheitToCelsius (double c)
{
double celsius;
for (double fahrenheit = 120.0; fahrenheit >= 30.0;
fahrenheit = fahrenheit - 10)
{
celsius = (fahrenheit - 32.0) * 5.0 / 9.0;
cout << fahrenheit << "\t\t" << celsius << endl;
}
cout << endl;
return celsius;
}
当我运行代码时得到什么
摄氏度华氏度 |华氏度
40.00 104.00 |
39.00 102.20 |
38.00 100.40 |
37.00 98.60 |
36.00 96.80 |
35.00 95.00 |
34.00 93.20 |
33.00 91.40 |
32.00 89.60 |
31.00 87.80 |
120.00 48.89
110.00 43.33
100.00 37.78
90.00 32.22
80.00 26.67
70.00 21.11
60.00 15.56
50.00 10.00
40.00 4.44
30.00 -1.11
-1.11 87.80
【问题讨论】:
-
使用 2 个字符串流,每个都用作单个页面的“列”。当每一列中的所有行都完成时,然后从每一列适当地 cout 到 std::cout。
标签: c++ function formatting format