Example solution for ELEC1620 Lab 2 Task 2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* ELEC1620 Lab 2 Task 2
00002 
00003 Currency Converter
00004 
00005 (c) Dr Craig A. Evans, Feb 2017
00006 
00007 */
00008 
00009 #include "mbed.h"
00010 
00011 // use pre-processor defines to set the conversion rate
00012 #define GBP2USD 1.26
00013 #define GBP2EUR 1.16
00014 #define GBP2CNY 8.65
00015 #define GBP2SAR 4.71
00016 
00017 int main()
00018 {
00019     printf("#### Currency Converter App ####\n\n");
00020     // current compiler version does not require 'f' flag for floating-point literals
00021     float gbp_value = 69.99;
00022 
00023     // do conversions
00024     float usd_value = GBP2USD * gbp_value;
00025     float eur_value = GBP2EUR * gbp_value;
00026     float cny_value = GBP2CNY * gbp_value;
00027     float sar_value = GBP2SAR * gbp_value;
00028 
00029     // print over serial 
00030     printf("GBP %.2f is equivalent to USD %.2f\n",gbp_value,usd_value);
00031     printf("GBP %.2f is equivalent to EUR %.2f\n",gbp_value,eur_value);
00032     printf("GBP %.2f is equivalent to CNY %.2f\n",gbp_value,cny_value);
00033     printf("GBP %.2f is equivalent to SAR %.2f\n",gbp_value,sar_value);
00034 
00035 }