我在這裏不知所措,所以我正在尋找任何提示以指引我朝着正確的方向前進。我不知道如何輸入我從華氏溫度轉換成攝氏溫度數組的攝氏度值。爲了這個目的,我嘗試在另一個for循環中工作,但它僅在第一個for循環的計算結果後輸出C的最後一個值。有任何想法嗎?提前致謝。在第一回路本身陣列中將數組中的數值放入另一個數組
// Temperature Converter
#include <iostream>
#include <iomanip>
using std::cout;
using std::endl;
using std::setw;
int main()
double temps[] = { 65.5, 68.0, 38.1, 75.0, 77.5, 76.4, 73.8, 80.1, 55.1, 32.3, 91.2, 55.0 };
double centigrade[] = { 0 }, C(0);
int i(0);
cout << setw(13) << "Farenheit " << setw(9) << " Centigrade";
cout << endl;
for (double t : temps)
{
C = (t - 32) * 5/9;
cout << setw(10) << t << setw(12) << C;
cout << endl;
}
for (i = 0; i <= 12; i++)
{
centigrade[i] = C;
cout << centigrade[i] << endl;
}
return 0;
}
你的'攝氏溫度'數組太小。你應該爲它分配一大塊內存。 – merlin2011
@ merlin2011太小了?那麼我應該把它改成'code'double centigrade [12]'code'? – user3465469
'double centigrade [12]'*** – user3465469