This is a currency converter program that converts amounts of different currencies entered into different currencies. It converts following currencies in between: Euro, British pound, Pakistani rupee, Canadian dollars, Australian dollars, and US dollars. This program can easily extended to include further currencies. You need to add two blocks of switch cases for new currency, define its conversion rate into US dollar and obviously enter a line for new currency in the option menu.

#include <iostream>  

#define EUR 0.80
#define GBP 0.63
#define PKR 101.75
#define CAD 1.13
#define AUD 1.16
#define USD 1.00
#define QUIT 6

 using namespace std;  
 int main()  
 {  
      float amount=0;  
      float rate1 = 0;
      float rate2 = 0;
      string cur_name1, cur_name2;
      char choice1, choice2, choice3='Y';  
      while (choice3=='Y' || choice3=='y')  
      {  
           cout<<"Select the currencies that you want to exchange\n";  
           cout<<" - Enter E for Euro\n";  
           cout<<" - Enter G for British Pound\n";  
           cout<<" - Enter P for Pakistani Rupee\n";  
           cout<<" - Enter C for Canadian Dollars\n";  
           cout<<" - Enter U for US Dollars\n";  
           cout<<" - Enter A for Australian Dollars\n"<<endl;  
           cout<<"Select Currency that you want to convert: ";  
           cin>>choice1;
           switch (choice1)  
           {  
           	  //convert PKR to USD
              case 'P':
                rate1 = 1/PKR;
                cur_name1 = "PKR";
				break;  
              //convert EUR to USD
              case 'E':
                rate1 = 1/EUR;
                cur_name1 = "EUR";
				break;  
              //convert GBP to USD
              case 'G':
                rate1 = 1/GBP;
                cur_name1 = "GBP";
				break;  
              //convert CAD to USD
              case 'C':
                rate1 = 1/CAD;
                cur_name1 = "CAD";
				break;  
              //convert AUD to USD
              case 'A':
                rate1 = 1/AUD;
                cur_name1 = "AUD";
				break;  
			  case 'U':
                rate1 = 1/USD;
                cur_name1 = "USD";
				break;  
              default: 
                cout<<"Please enter a valid option."<<endl<<endl;
                continue;
           } 
           
           cout<<"Select Currency that you want to convert Into: ";  
           cin>>choice2; 
		   switch (choice2)  
           {  
           	  //convert rate1 to required rate i.e rate2
              case 'A':
                rate2 = rate1*AUD;
                cur_name2 = "AUD";
				break;  
           	  //convert rate1 to required rate i.e rate2
              case 'P':
                rate2 = rate1*PKR;
				cur_name2 = "PKR";
				break;  
           	  //convert rate1 to required rate i.e rate2
              case 'E':
                rate2 = rate1*EUR;
                cur_name2 = "EUR";
				break;  
           	  //convert rate1 to required rate i.e rate2
              case 'G':
                rate2 = rate1*GBP;
                cur_name2 = "GBP";
				break;  
           	  //convert rate1 to required rate i.e rate2
              case 'C':
                rate2 = rate1*CAD;
                cur_name2 = "CAD";
				break;  
			  //convert rate1 to required rate i.e rate2
              case 'U':
                rate2 = rate1*USD;
                cur_name2 = "USD";
				break;  
              default: 
                cout<<"Please enter a valid option."<<endl<<endl;
                continue;
           } 
           cout<<"Enter Amount: ";  
           cin>>amount; 
           rate2 = rate2*amount;
	   cout<<endl<<amount <<" "<<cur_name1<<" = "<< rate2 << " " << cur_name2<<endl<<endl;
	   cout<<"Run Again(Y/N): ";  
           cin>>choice3;
      }	   
      cout<<"Ciao "<<endl;
 }    

Sample Output

currency converter

Tagged with: C/C++ languageSource Code
 

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Related News Feeds

Set your Twitter account name in your settings to use the TwitterBar Section.