From 3b1f24fd1c9b11351d26427306e107662ce8537a Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Fri, 10 Feb 2023 21:53:26 +0100 Subject: [PATCH] Revert "Refactor currencyExchange" This reverts commit 7236756d50ad51505e2bc8c81038aabe949c52ab. --- src/currencyExchange.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/currencyExchange.c b/src/currencyExchange.c index 4d3cec5..83bf372 100644 --- a/src/currencyExchange.c +++ b/src/currencyExchange.c @@ -1,18 +1,20 @@ #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; -} +} \ No newline at end of file