I prefer my version that's half as long and does the same xD

And for displaying a fixed number of decimals:
#include <iomanip>

Then just before the cout (only the first time):
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(number_of_decimals_here);


Or for rounding (warning, this comes from the web, in case your teacher checks):
Code:
float Round(float Value, int NumPlaces)
   {
   int k, Temp;
   float Factor;
   
   Factor = 1;
   for (k = 0; k < NumPlaces; k++)
      Factor = Factor * 10;
      
   Temp = Value * Factor + 0.5;
   return Temp / Factor;
   }