dollar currency converter

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 4 Try This page 105
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PP
//	Chapter 4 Try This page 105

#include "std_lib_facilities.h"

int main()
{
	const double yenToDollar = 101.10;
	const double euroToDollar = 0.89;
	const double poundToDollar = 0.76;

	

	double dollar = 1;
	char currency = 'a';

	cout << "Please enter an amount of dollar(s) you want to convert,\nfollowed by the desired conversion currency (yen = y, euro = e, pound = p): \n";
	cin >> dollar >> currency;
	
	if (currency == 'y')
	{
		if (dollar*yenToDollar <= 1)
		{
			cout << dollar << " dollar is " << dollar*yenToDollar << " yen";
		}
		else
		{
			cout << dollar << " dollars are " << dollar*yenToDollar << " yen\n";
		}
	}
	else if(currency == 'e')
	{
		if (dollar*euroToDollar <= 1)
		{
			cout << dollar << " dollar is " << dollar*euroToDollar << " euro\n";
		}
		else
		{
			cout << dollar << " dollars are " << dollar*euroToDollar << " euros\n";
		}
	}
	else if (currency == 'p')
	{
		if (dollar*euroToDollar <= 1)
		{
			cout << dollar << " dollar is " << dollar*poundToDollar << " pound\n";
		}
		else
		{
			cout << dollar << " dollars are " << dollar*poundToDollar << " pounds\n";
		}
	}
	else
	{
		cout << "I dont know what " << currency << " for an currency is\n";
	}
	
	keep_window_open();
}
Output:
Please enter an amount of dollar(s) you want to convert,
followed by the desired conversion currency (yen = y, euro = e, pound = p):
130 y
130 dollars are 13143 yen
Please enter a character to exit

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.