Gold University of Minnesota M. Skip to main content.University of Minnesota. Home page.
 
 
 

What's inside.

Ta Email

Download Compiler

Final Project

Lab Notes

Office Hours

Schedule

Syllabus

Announcements

Check Grades

 

CSci 1113 Home

 
 

Printer-friendly version

 
Currency Conversion Table Using a for Loop

% cat currency.cpp
// Currency conversion - dollars to euros
#include <iostream>
using namespace std;
#include <iomanip>

int main()
{
  double i, dollar, euro, rate = 1.35;

  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(2);

  cout << setw(10) << "Dollars" << setw(10) << "Euros" << endl;

  for(i=0.0; i <= 100.0; i += 5.0)
  {
     cout << setw(10) << i << setw(10) << i/rate << endl;
  }

  return 0;
}
cswanson@shemp (~/spr08) % g++ currency.cpp
cswanson@shemp (~/spr08) % a.out
   Dollars     Euros
      0.00      0.00
      5.00      3.70
     10.00      7.41
     15.00     11.11
     20.00     14.81
     25.00     18.52
     30.00     22.22
     35.00     25.93
     40.00     29.63
     45.00     33.33
     50.00     37.04
     55.00     40.74
     60.00     44.44
     65.00     48.15
     70.00     51.85
     75.00     55.56
     80.00     59.26
     85.00     62.96
     90.00     66.67
     95.00     70.37
    100.00     74.07

 
The University of Minnesota is an equal opportunity educator and employer.
CSci 1113: C++ Programming