0

Why does the following code only produce an integer?

Please review the below. I totally get that if x was declared as an INT then the answer should be 3 (and we could use % to get the remainder). What I don't understand is why the code below still returns an answer of 3. I declared x as a float, so shouldn't the answer be 3.33? #include <iostream> using namespace std; int main() { float x = 10 / 3; cout << x; return 0; // Returns 3, why not 3.33? // }

9th Dec 2018, 5:24 PM
Zachary Werde
Zachary Werde - avatar
2 Réponses
0
Jamie💐 Thanks! So you are saying that by rule the division operator always returns an INT value even if the variable is declared as a float?
9th Dec 2018, 5:33 PM
Zachary Werde
Zachary Werde - avatar
0
Jamie💐 Awesome...will give it a whirl...thanks!
9th Dec 2018, 5:42 PM
Zachary Werde
Zachary Werde - avatar