#include <iostream>
static const double US_TO_MXN = 12.99 ;
static const char DATA_DATE[ ] = "6/12/2014" ;
void convert( const char * from, const char * to, double exchange)
{
std:: cout << "Enter the number of " << from << " to convert to " << to << ".\n "
"Amount: " ;
int original;
std:: cin >> original;
std:: cout << to << ": " << ( original * exchange) << '\n ' ;
}
int main( ) // this is valid since C++2003
{
std:: cout << "US/MXN Converter\n "
"1 US = " << US_TO_MXN << " MXN (" << DATA_DATE << ")\n "
"\n " ;
int choice = 0 ;
// Here's a better demonstration of goto
GET_CHOICE:
std:: cout << "Which conversion do you want to perform?\n "
"[1] US to MXN\n "
"[2] MXN to US\n "
"Selection: " ;
std:: cin >> choice;
if ( choice == 1 )
convert( "US Dollars" , "Pesos" , US_TO_MXN) ;
else if ( choice == 2 )
convert( "Pesos" , "US Dollars" , 1 / US_TO_MXN) ;
else {
std:: cerr << "Invalid choice. Please try again.\n " ;
goto GET_CHOICE;
}
// this also serves to demonstrate that goto is bad because
// it's not obvious from the above that you have a loop.
}
ICAgICNpbmNsdWRlIDxpb3N0cmVhbT4KCiAgICBzdGF0aWMgY29uc3QgZG91YmxlIFVTX1RPX01YTiA9IDEyLjk5OwogICAgc3RhdGljIGNvbnN0IGNoYXIgREFUQV9EQVRFW10gPSAiNi8xMi8yMDE0IjsKCiAgICB2b2lkIGNvbnZlcnQoY29uc3QgY2hhciogZnJvbSwgY29uc3QgY2hhciogdG8sIGRvdWJsZSBleGNoYW5nZSkKICAgIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgIkVudGVyIHRoZSBudW1iZXIgb2YgIiA8PCBmcm9tIDw8ICIgdG8gY29udmVydCB0byAiIDw8IHRvIDw8ICIuXG4iCiAgICAgICAgICAgICAgICAgICAgICJBbW91bnQ6ICI7CiAgICAgICAgaW50IG9yaWdpbmFsOwogICAgICAgIHN0ZDo6Y2luID4+IG9yaWdpbmFsOwogICAgICAgIHN0ZDo6Y291dCA8PCB0byA8PCAiOiAiIDw8IChvcmlnaW5hbCAqIGV4Y2hhbmdlKSA8PCAnXG4nOwogICAgfQoKICAgIGludCBtYWluKCkgIC8vIHRoaXMgaXMgdmFsaWQgc2luY2UgQysrMjAwMwogICAgewogICAgICAgIHN0ZDo6Y291dCA8PCAiVVMvTVhOIENvbnZlcnRlclxuIgogICAgICAgICAgICAgICAgICAgICAiMSBVUyA9ICIgPDwgVVNfVE9fTVhOIDw8ICIgTVhOICgiIDw8IERBVEFfREFURSA8PCAiKVxuIgogICAgICAgICAgICAgICAgICAgICAiXG4iOwoKICAgICAgICBpbnQgY2hvaWNlID0gMDsKICAgICAgICAvLyBIZXJlJ3MgYSBiZXR0ZXIgZGVtb25zdHJhdGlvbiBvZiBnb3RvCiAgICBHRVRfQ0hPSUNFOgogICAgICAgIHN0ZDo6Y291dCA8PCAiV2hpY2ggY29udmVyc2lvbiBkbyB5b3Ugd2FudCB0byBwZXJmb3JtP1xuIgogICAgICAgICAgICAgICAgICAgICJbMV0gVVMgdG8gTVhOXG4iCiAgICAgICAgICAgICAgICAgICAgIlsyXSBNWE4gdG8gVVNcbiIKICAgICAgICAgICAgICAgICAgICAiU2VsZWN0aW9uOiAiOwogICAgICAgIHN0ZDo6Y2luID4+IGNob2ljZTsKCiAgICAgICAgaWYgKGNob2ljZSA9PSAxKQogICAgICAgICAgICBjb252ZXJ0KCJVUyBEb2xsYXJzIiwgIlBlc29zIiwgVVNfVE9fTVhOKTsKICAgICAgICBlbHNlIGlmIChjaG9pY2UgPT0gMikKICAgICAgICAgICAgY29udmVydCgiUGVzb3MiLCAiVVMgRG9sbGFycyIsIDEgLyBVU19UT19NWE4pOwogICAgICAgIGVsc2UgewogICAgICAgICAgICBzdGQ6OmNlcnIgPDwgIkludmFsaWQgY2hvaWNlLiBQbGVhc2UgdHJ5IGFnYWluLlxuIjsKICAgICAgICAgICAgZ290byBHRVRfQ0hPSUNFOwogICAgICAgIH0KCiAgICAgICAgLy8gdGhpcyBhbHNvIHNlcnZlcyB0byBkZW1vbnN0cmF0ZSB0aGF0IGdvdG8gaXMgYmFkIGJlY2F1c2UKICAgICAgICAvLyBpdCdzIG5vdCBvYnZpb3VzIGZyb20gdGhlIGFib3ZlIHRoYXQgeW91IGhhdmUgYSBsb29wLgogICAgfQo=