Example solution for ELEC1620 Lab 2 Task 2

Dependencies:   mbed

main.cpp

Committer:
eencae
Date:
2017-02-02
Revision:
0:9f7e104e4cb9

File content as of revision 0:9f7e104e4cb9:

/* 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);

}