我不知道爲什麼當我執行這個程序時浮動不能打印確切的值的原因。浮動不能正常工作
#include <iostream>
using namespace std;
int main(){
int a, b;
float x;
cout << "Input the value for a: ";
cin >> a;
cout << "Input the value for b: ";
cin >> b;
x = - b/a;
printf("The value of x is: %.2f",x);
//cout << "The value of x is: " << x;
}
我想至少在我的輸入2和10 b的結果應該是0.20, 程序顯示0.00只
不會給出商。所以結果仍然是5 – jonju
所以我不能得到浮動答案像1.5如果我的操作數是整數? – Marr