I need to make a program to calculate the volume of a sphere with the formula V=(4/3)*pi*r^3
What is the difference between
volume_sphere = (4/3)*pi*r*r*r;
and
volume_sphere = (4/3.0)*pi*r*r*r;
?
When I input the 3 as the value for my r, the former gave me a wrong answer (84.823196). However, when I used the latter one (with the ".0"), it gave me the right answer (113.0976).
I am so confused with the ".0" difference. Thank you for answering!