Cpp - Write program to use nested while loop to output exchange rate

Requirements

Rewrite the following code with nested while loop

#include <iostream> 
#include <iomanip> 
using namespace std; 

int main() 
{ 
   long   euro, maxEuro;     // Amount in Euros 
   double rate;              // Exchange rate Euro <-> $ 

   cout << "\n* * * TABLE OF EXCHANGE " 
         <<  " Euro - US-$ * * *\n\n"; 

   cout << "\nPlease give the rate of exchange: " 
              " one Euro in US-$: "; 
   cin >> rate; 
   cout << "\nPlease enter the maximum euro: "; 
   cin >> maxEuro; 
   // Titles of columns: 
   cout << '\n' 
         << setw(12) << "Euro" << setw(20) << "US-$" 
         << "\t\tRate: " << rate << endl; 

   // Formatting US-$: 
   cout << fixed << setprecision(2) << endl; 

   long lower, upper,         // Lower and upper limit 
        step;                 // Step width 

   for( lower=1, step=1; lower <= maxEuro; step*= 10, lower = 2*step) 
      for( euro = lower, upper = step*10; euro <= upper && euro <= maxEuro; euro+=step) 
        cout << setw(12) << euro << setw(20) << euro*rate << endl; 
   return 0; 
} 

Demo

#include <iostream> 
#include <iomanip> 
using namespace std; 

int main() /*from www. j  av a  2  s  .  c  om*/
{ 
   long   euro, maxEuro;     // Amount in Euros 
   double rate;              // Exchange rate Euro <-> $ 

   cout << "\n* * * TABLE OF EXCHANGE " 
         <<  " Euro - US-$ * * *\n\n"; 

   cout << "\nPlease give the rate of exchange: " 
              " one Euro in US-$: "; 
   cin >> rate; 
   cout << "\nPlease enter the maximum euro: "; 
   cin >> maxEuro; 
   // Titles of columns: 
   cout << '\n' 
         << setw(12) << "Euro" << setw(20) << "US-$" 
         << "\t\tRate: " << rate << endl; 

   // Formatting US-$: 
   cout << fixed << setprecision(2) << endl; 

   long lower, upper,         // Lower and upper limit 
        step;                 // Step width 

    lower=1, step=1; 
    while( lower <= maxEuro) 
    { 
                          // The inner loop outputs a block: 
    
         euro = lower; 
         upper = step*10; 
         while( euro <= upper && euro <= maxEuro) 
         { 
            cout << setw(12) << euro 
                 << setw(20) << euro*rate << endl; 
            euro += step; 
          } 
          step *= 10, lower = 2*step; 
    } 
   return 0; 
}

Result

Related Exercise