2010-11-16 44 views
0

這個程序將攝氏度轉換成華氏度和開爾文。 當我在Dev C++中運行此代碼時,我將攝氏度值從2變爲300.如何獲取代碼輸出從-300開始到300結束的攝氏溫度值?
我明確地在for循環中設置了cels = -300。那麼爲什麼輸出從2開始?
我該怎麼做才能在C++中擴展輸出值

#include <iostream> 
#include <iomanip> 
#include <cmath> 
using namespace std; 
int main() 
{ 
double cels, fah, kel, cels2fah, cels2kel, fah2cels, fah2kel; 
cout<<"My Name \n"; 
cout<<"Program 8.0 "<<endl; 
cout<<"\n\n"; 
cout<<"Celsius  Fahrenheit  Kelvin \n" 
    <<"Degrees  Degrees   --------\n" 
    <<"-------- -----------  --------\n"; 


for(cels = -300; cels<= 300; cels++) 
{ 
cels2fah = (cels*9.0/5)+32.0; 
cels2kel = cels+273.15; 
setprecision(4.0); 
cout<<setw(3)<< cels <<" " 
    <<setw(12)<< cels2fah <<" " 
    <<setw(14)<< cels2kel <<" \n"; 
} 
system("PAUSE"); 
return 0; 
} 
+4

問題是? – g19fanatic 2010-11-16 04:28:08

+0

代碼工作正常。什麼是問題? – Alam 2010-11-16 04:34:04

+0

使用浮點類型(cels)作爲循環增量變量是個好主意嗎? – Chubsdad 2010-11-16 04:34:34

回答

2

我想輸出滾動作爲有太多的線條在屏幕上的緩衝區,以保持(試過在VS 2010/XP)。最後的輸出只有2行到300行。

不要擔心,輸出是打印,但至少在Windows的最終窗口中看不到。

嘗試將輸出記錄到輸出文件。

+0

Yikes - 很好找到:-)。 – 2010-11-16 04:42:57

+0

也可以通過右鍵單擊標題欄,選擇「屬性」 - >「佈局」,然後更改屏幕緩衝區大小來擴展控制檯緩衝區的大小。 – 2010-11-16 05:21:55

+0

謝謝,這也非常有幫助。 – user507879 2010-11-16 05:25:38

相關問題