Preview:
/*
 Author:	Internshala
 Module:	Diving into C++ Programming
 Topic:		Namespaces
*/

#include <iostream>
using namespace std;

namespace jp {

	float dollarValue = 108;	// 1 USD = 108 Japanese Yen

	double toDollars(float currencyUnits) {
		return currencyUnits / dollarValue;
	}
}

namespace cn {

	float dollarValue = 7;		// 1 USD = 7 Chinese Yuan

	double toDollars(float currencyUnits) {
		return currencyUnits / dollarValue;
	}
}


int main() {

	cout << "1 USD = " << jp::dollarValue << " Yen" << endl;
	cout << "1 USD = " << cn::dollarValue << " Yuan" << endl;

	cout << "8960 Yen = " << jp::toDollars(8960) << " USD" << endl;
	cout << "610 Yuan = " << cn::toDollars(610) << " USD" << endl;

	return 0;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter