每當我嘗試編譯,我得到將int轉換爲float?
24【警告】從float
83 [預警]轉換爲int
從float
int a , b = 8;
float c = 5.2;
float d = 8E3;
a = static_cast<float>(b) * c; // 24
cout << a << "\n";
cout << d << "\n";
int x, y, answer;
x = 7;
y = 9;
answer = 5;
answer *= (x + y);
cout << answer << "\n";
answer *= x + y;
cout << answer << "\n";
float m = 33.97;
answer += (x + y + m); // 83
cout << answer << "\n";
任何建議轉換爲int
到我的什麼做錯了?
'a'是一個int,'b * c'是一個浮點數。 – Adam
您不需要將整數轉換爲浮點數,因爲不會因爲編譯器自動完成轉換而丟失精度。 –