home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / AlexNeXTSTEPSource / Source / Chapter6_Events / Money / MoneyConverter.m < prev    next >
Encoding:
Text File  |  1993-04-08  |  976 b   |  43 lines

  1. /* Generated by Project Builder */
  2.  
  3. #import <appkit/appkit.h>
  4. #import "MoneyConverter.h"
  5.  
  6. #define MAXIMUM 6
  7.  
  8. @implementation MoneyConverter
  9.  
  10. - convert:sender
  11. {
  12.     int index, loop;
  13.     float entry, value, dollar_equiv;
  14.     
  15.     // Array contains the conversion of rates
  16.     // of other currencies to dollars
  17.     static float rate[MAXIMUM] =
  18.         {1.00, 135.0, 0.50, 1.67, 6.00, 14.5};
  19.     
  20.     // Determine which field of the form
  21.     // was the last to be edited
  22.     index = [moneyForm selectedIndex];
  23.     
  24.     // Calculate equivalent of foreign currency
  25.     // at edited field to dollar equivalent
  26.     entry = [moneyForm floatValueAt:index];
  27.     dollar_equiv = entry / rate[index];
  28.     for (loop = 0; loop < MAXIMUM; loop++)
  29.         {
  30.         // Calculate other currencies
  31.         // using look-up table
  32.         value = dollar_equiv * rate[loop];
  33.         // display value at appropriate field
  34.         [moneyForm setFloatValue:value at:loop];
  35.         }
  36.     // leave the last edited field as the
  37.     // selected text
  38.     [moneyForm selectTextAt:index];
  39.     return self;
  40. }
  41.  
  42. @end
  43.