There are several small things that you can improve:
double weight = 0;
works fine, butdouble weight = 0.0;
would be more pedantic sinceweight
is adouble
.By the way, the following line is a good example to illustrate the benefits of literals pedantry:
double volume = ((4/3) * M_PI * pow(obj.radius, 3));
Here,
4/3
performs an integer division and not a floating point one; that expression will yield1
instead of1.333333333
(I doubt that you want it to yield1
). You should change it to4.0/3.0
to get the desired result.That said, there is another problem with the aforementioned line:
M_PI
is not standard C++. It is not standard C either. It is a standard POSIX addition to<math.h>
. You should rewrite your own constants or use Boost ones for examples if you want your code to be portable.Speaking of
<math.h>
... You are using C++, therefore you should use the C++ standard library headers too and not the C ones:#include <cmath>
And you notably forgot to include the header
<cctype><ctype.h>
forstd::tolower
.AlsoThat said, it is good practice in C++ to fully qualify the names of the functions from the standard library: you should write
std::tolower
(and thus actually include<cctype>
instead of<ctype.h>
). It's not really longer and it may help to prevent name clashes (I doubt that you will have problems withtolower
, but it can be worse with some more common names).