|
@ -1,17 +1,19 @@ |
|
|
#include "currencyExchange.h" |
|
|
#include "currencyExchange.h" |
|
|
|
|
|
|
|
|
#define NUM_CURRENCIES 4 |
|
|
|
|
|
|
|
|
float convert(float euro, int newCurrencyCode) { |
|
|
|
|
|
switch(newCurrencyCode) { |
|
|
|
|
|
case CURRENCY_CODE_USD: |
|
|
|
|
|
return ( euro * USD_RATE_OF_ONE_EURO ); |
|
|
|
|
|
|
|
|
float exchangeRates[NUM_CURRENCIES] = { |
|
|
|
|
|
USD_RATE_OF_ONE_EURO, |
|
|
|
|
|
GBP_RATE_OF_ONE_EURO, |
|
|
|
|
|
JAPANESE_YEN_RATE_OF_ONE_EURO, |
|
|
|
|
|
CHINESE_YUAN_RATE_OF_ONE_EURO |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
case CURRENCY_CODE_GBP: |
|
|
|
|
|
return ( euro * GBP_RATE_OF_ONE_EURO ); |
|
|
|
|
|
|
|
|
|
|
|
case CURRENCY_CODE_JAPANESE_YEN: |
|
|
|
|
|
return ( euro * JAPANESE_YEN_RATE_OF_ONE_EURO ); |
|
|
|
|
|
|
|
|
|
|
|
case CURRENCY_CODE_CHINESE_YUAN: |
|
|
|
|
|
return ( euro * CHINESE_YUAN_RATE_OF_ONE_EURO ); |
|
|
|
|
|
|
|
|
float convert(float euro, int newCurrencyCode) { |
|
|
|
|
|
if (newCurrencyCode >= 0 && newCurrencyCode < NUM_CURRENCIES) { |
|
|
|
|
|
return euro * exchangeRates[newCurrencyCode]; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return -1; |
|
|
return -1; |