【发布时间】:2017-09-18 05:06:21
【问题描述】:
我是 C++ 初学者,想做this 练习。以下是我的代码,但我不知道为什么在 cout 循环时它不显示下限。
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double low=-0.000001, high=-0.000001, step=0.0, stop, f;
while (low <= -0.000001 || low > 50000) {
cout << "Lower limit (0~50,000): "; cin >> low;
if (low <= -0.000001) {cout << "Must be positive." << endl;}
else if (low > 50000) {cout << "Out of range." << endl;}
}
while (high <= -0.000001 || high > 50000 || high <= low) {
cout << "Higher limit (0~50,000): "; cin >> high;
if (high <= -0.000001) {cout << "Must be positive." << endl;}
else if (high > 50000) {cout << "Out of range." << endl;}
else if (high <= low) {cout << "Must higher than lower limit." << endl;}
}
while (step <= 0 || step > high) {
cout << "Step (0.000001~" << high << "): "; cin >> step;
if (step <= 0) {cout << "Must be positive." << endl;}
else if (step > high) {cout << "Out of range." << endl;}
}
cout << endl << "Celsius\t\tFahrenheit" << endl;
cout << "-------\t\t----------" << endl;
stop = low;
while (stop < high) {
f = 1.8 * stop + 32.0;
stop += step;
cout << fixed << setprecision(6) << stop << "\t" << fixed << setprecision(6) << f << endl;
}
return 0;
}
例如,如果我输入 1.5 作为下限,我想它的输出应该以 1.5 开头,但它以 2.0 开头...我该如何解决这个问题?谢谢。
【问题讨论】:
标签: c++ while-loop converter temperature