Cpp - Outputs a table of exchange: Euro and US-$ using for loop

Description

Outputs a table of exchange: Euro and US-$ using for loop

Demo

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

int main() /*from  w  w  w.j  a v  a2 s.  c  o  m*/
{ 
   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; 
}

Result

Related Example