-2

I want to write 4/3 as a fraction in C++. I know that 4/3 is equal to 1.33333. But when I write 4/3 in the code it outputs it's quotient which is 1. Can anyobody tell me how to write this number as fraction?

The code:

double vol_sphere(double radiusS){
     return (4/3) * pi * pow(radiusS, 3);
}
Croolman
  • 1,103
  • 13
  • 40

1 Answers1

1

Because 4 and 3 are both integers, when you perform division of two integers, the result will be also integer, so 1.333333333 will be only 1.

AbdelAziz AbdelLatef
  • 3,650
  • 6
  • 24
  • 52