Craig Evans
/
1620_Lab2_Task2
Example solution for ELEC1620 Lab 2 Task 2
Revision 0:9f7e104e4cb9, committed 2017-02-02
- Comitter:
- eencae
- Date:
- Thu Feb 02 14:01:48 2017 +0000
- Commit message:
- Example solution for ELEC1620 Lab 2 Task 2
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Feb 02 14:01:48 2017 +0000 @@ -0,0 +1,35 @@ +/* ELEC1620 Lab 2 Task 2 + +Currency Converter + +(c) Dr Craig A. Evans, Feb 2017 + +*/ + +#include "mbed.h" + +// use pre-processor defines to set the conversion rate +#define GBP2USD 1.26 +#define GBP2EUR 1.16 +#define GBP2CNY 8.65 +#define GBP2SAR 4.71 + +int main() +{ + printf("#### Currency Converter App ####\n\n"); + // current compiler version does not require 'f' flag for floating-point literals + float gbp_value = 69.99; + + // do conversions + float usd_value = GBP2USD * gbp_value; + float eur_value = GBP2EUR * gbp_value; + float cny_value = GBP2CNY * gbp_value; + float sar_value = GBP2SAR * gbp_value; + + // print over serial + printf("GBP %.2f is equivalent to USD %.2f\n",gbp_value,usd_value); + printf("GBP %.2f is equivalent to EUR %.2f\n",gbp_value,eur_value); + printf("GBP %.2f is equivalent to CNY %.2f\n",gbp_value,cny_value); + printf("GBP %.2f is equivalent to SAR %.2f\n",gbp_value,sar_value); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Feb 02 14:01:48 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ad3be0349dc5 \ No newline at end of file