Calculate volume of a cylinder with user input I'm looking for a fast OR simple way to calculate the volume of a user-entered cylinder.  Here is my solution:

#include &lt;iostream&gt;
using namespace std;
#include &lt;math.h&gt;

int main()
{
    long double pi = acos(-1);
    cout.precision(1000);
    long double radius;
    long double volume;
    long double height;
    cout &lt;&lt; "Hello to the cylinder volume solver!" &lt;&lt; endl;
    cout &lt;&lt; "Please enter the cylinder's radius: ";
    cin &gt;&gt; radius;
    long double radius_sq = radius * radius;
    cout &lt;&lt; endl &lt;&lt; "Please enter the cylinder's height: ";
    cin &gt;&gt; height;
    volume = pi * radius_sq * height;
    cout &lt;&lt; endl &lt;&lt; "The cylinder's volume is " &lt;&lt; volume &lt;&lt; "." &lt;&lt; endl;
    return 0;
}


It's obvious to see that I'm a new programmer from the way I wrote this....which is why I want to learn from your remarks.
Your implementation is quite simple,
but a bit hard to read:


It's a wall of code, with no vertical spacing to visual separate closely related groups
The ordering of statements is haphazard, with no discernible underlying logic


Consider this alternative:

#include &lt;iostream&gt;
#include &lt;cmath&gt;

long double calculateCylinderVolume(long double radius, long double height)
{
    return acos(-1) * radius * radius * height;
}

int main()
{
    std::cout &lt;&lt; "Hello to the cylinder volume solver!\n";

    std::cout &lt;&lt; "Please enter the cylinder's radius: ";
    long double radius;
    std::cin &gt;&gt; radius;

    std::cout &lt;&lt; "\nPlease enter the cylinder's height: ";
    long double height;
    std::cin &gt;&gt; height;

    std::cout.precision(1000);
    std::cout &lt;&lt; "\nThe cylinder's volume is "
        &lt;&lt; calculateCylinderVolume(radius, height) &lt;&lt; ".\n";
}


Notice that:


variables are not declared sooner than really needed
the std::cout.precision(1000); is delayed until it's actually needed
the blank lines visually separate the closely related statements, improving readability


Other minor improvements:


using namespace std is considered bad practice
return 0 at the end of main is unnecessary
\n is more efficient than std::endl
#include &lt;cmath&gt; instead of #include &lt;math.h&gt;, as pointed out by @FredLarson