我想知道如何使用void函數輸出基於條件的結果。我正在嘗試創建一個Windchill計算器。如何在C++中操作函數根據條件輸出不同的結果?
我可以添加什麼使下面的程序輸出的氣溫低於4.8kph的速度? 我可以做些什麼來使print_result無效,以便打印各種語句 - 比如-20至-30°的windchill(WC)的「wear 3 layers」或者-30 to -40的wear 5 layers?感謝那些能夠幫助的人!
#include <iostream>
#include <cmath>
using namespace std;
bool is_cold(double V)
{
bool is_windy;
if (V <= 4.8)
{
is_windy = false;
}
else
is_windy = true;
return (is_windy);
}
int windchill_index(double T, double V)
{
int WC;
WC = 13.12 + 0.6215*T - 11.37*pow(V,0.16) + 0.3965*T*pow(V, 0.16);
return (WC);
}
void print_result(double WC)
{
cout << "From the input for tempearature and wind speed, the wind chill is: "<< WC << endl;
}
int main()
{
double WC = 0, T = 0, V = 0;
bool is_windy = false;
if (!is_windy)
{
cout << "Please enter the air temperature in Celsius followed by the windpseed in kph: " << endl;
cin >> T;
cin >> V;
is_windy = is_cold(V);
}
WC = windchill_index(T, V);
print_result (WC);
return 0;
}
嗯...'if'報表? –