//  neatColumns3.cpp
//
//  Displays table of powers of two,
//  with right-justified columns,
//  but without the setw manipulator.

#include <iostream>

using namespace std;

int main()
{
   cout << "Powers of two" << endl;
   cout << "-------------" << endl << endl;
   cout << "Exponent     Power" << endl;
   cout << "--------     -----" << endl << endl;

   int powerOfTwo = 1;
   for ( int exponent = 0; exponent <= 16; exponent++ )
   {
      //Display right-justified left column:
      cout << "   ";
      if ( exponent < 10 )
         cout << " ";   // leading space
      cout << exponent;

      // Determine width of right column
      // not including leading spaces:
      int digitCount = 1;
      int powerOfTen = 10;
      while ( powerOfTen <= powerOfTwo )  {
         digitCount++;
         powerOfTen = powerOfTen * 10;
      }  // while

      // Display right-justified right column:
      cout << " ";
      for ( int i = digitCount; i < 11; i++ )
         cout << " ";
      cout <<  powerOfTwo << endl;

      // Loop update:
      powerOfTwo = powerOfTwo * 2;
   }  // while

   return 0;
}  // function main