//---------------------------------------------------------------------------
/****************************************************************************
練習5-1:寫一個程式進行攝氏溫度轉換成華氏溫度。 *
****************************************************************************/
#include <iostream>
//---------------------------------------------------------------------------
float C_temparature;
float F_tempature;
int main(int argc, char* argv[])
{
std::cout << "Enter the degrees of centigrade temparature, and system "
<< '\n' <<"will changeit it to Fahrenheit tempararture: ";
std::cin >> C_temparature;
F_tempature = ( 9/5 * C_temparature ) + 32;
std::cout << "The Fahrenheit temparature: " << F_tempature << '\n';
std::system("pause");
return 0;
}
//---------------------------------------------------------------------------
這樣印出的答案會是錯的,Why?
因為 9/5 是整數除法=1,所以要將它改成 9.0/.50 ~
題目來源:C++風格與藝術 第二版 Steve Oualline 著 黃吉霈 編譯
答案來源:自我撰寫(不保證正確喔)
留言列表