0
    int r = 10;
    double pi = 3.141;
    double vol1 = 4 * pi / 3 * r * r * r; //4188.0
    double vol2 = pi * r * r * r * (4 / 3);//3141.0
    

Why do the two calculations vol1 and vol2 give two different results? The order of operations says that parentheses are the only precedence to consider and it should not affect the result?

Geeniee
  • 7
  • 4
  • "*Why do these two expressions give the same result?*" - "*Why do the two calculations vol1 and vol2 give two different results?*" --- Please take more care when composing the question - especially when composing the title. – Turing85 Jan 08 '22 at 13:41
  • `(4 / 3)` -> `(4.0 / 3)` –  Jan 08 '22 at 13:43
  • why does that change the result? @英語は苦手 – Geeniee Jan 08 '22 at 13:46
  • 1
    4/3 is integer division and equals 1. 4.0/3 is float division and equals about 1.33. – matt Jan 08 '22 at 13:47

0 Answers0