Pure Programmer

## Project: Milky Way Stellar Density Estimate

Estimate the average [[stellar density]] of the [[Milky Way]] Galaxy. The stellar density is the number of stars per volume. Assume that the volume of the Milky Way is calculated as in project MilkyWayVolume and that the number of stars is 100 - 400 billion. Because we don't know the exact number of stars, allow the user to pass the number of stars in on the command line.

Also compute the size of box with a star in the middle that would correspond to the stellar density calculated. (Hint: Take the cube root of the reciprocal of the stellar density) This is the average distance between stars if the the galaxy were homogenious (which it is not) and if stars were stacked in little boxes of the same size (which they are not). What would the number of stars need to be in order to correspond to the distance to our nearest neighbor star [[Proxima Centauri]] at 4.2465 light-years?

Output
\$ g++ -std=c++17 MilkyWayStellarDensity.cpp -o MilkyWayStellarDensity -lfmt \$ ./MilkyWayStellarDensity 100000000000 The Milky Way stellar density ≈ 1.004e-02 stars per light-year³ The average distance between stars ≈ 4.635e+00 light-years \$ g++ -std=c++17 MilkyWayStellarDensity.cpp -o MilkyWayStellarDensity -lfmt \$ ./MilkyWayStellarDensity 400000000000 The Milky Way stellar density ≈ 4.017e-02 stars per light-year³ The average distance between stars ≈ 2.920e+00 light-years

Solution