Find diameter from volume of sphere C++ -
this question has answer here:
i have got task create program calculates diameter of sphere of volume 1234.67 cu meters.
i have written following code : -
#include <iostream> #include <math.h> using namespace std; int main(){ float vol, dm, h; vol = 1234.67; cout << "calculating diameter of sphere volume 1234.67 cu meters" << endl; h = vol*(3/4)*(7/22); dm = 2 * cbrt(h); cout << "the diameter of sphere volume 1234.67 cu meters " << dm << endl; return 0; }
what's wrong program , gives 0 output
calculating diameter of sphere volume 1234.67 cu meters diameter of sphere volume 1234.67 cu meters 0
h = vol * (3 / 4) * (7 / 22);
should be
h = vol * (3.f / 4.f) * (7.f / 22.f);
as int
3 / 4 == 0
.
Comments
Post a Comment