Wednesday, August 6, 2025

CURRENCY CONVERTER 2.0

 #include <iostream>

#include<map>
#include<string>
using namespace std;
class currency{
    map<pair<string,string>,double>converter;

public:
currency(){
    converter[{"USD", "INR"}] = 83.12;
        converter[{"INR", "USD"}] = 0.012;
        converter[{"USD", "KWD"}] = 0.31;
        converter[{"KWD", "USD"}] = 3.25;
        converter[{"GBP", "INR"}] = 105.6;
        converter[{"INR", "GBP"}] = 0.0094;
        converter[{"AED", "USD"}] = 0.27;
        converter[{"USD", "AED"}] = 3.67;
}
void convert(){
    string fromCurrency,toCurrency;
    float amount;
    cout<<"\navailable currencies:USD,INR,KWD,GBP,AED\n";
    cout<<" enter from currency code "<<endl;
    cin>>fromCurrency;
    cout<<" enter to currency code "<<endl;
    cin>>toCurrency;
    cout<<" enter amount "<<endl;
    cin>>amount;
    pair<string,string>key={fromCurrency,toCurrency};
    if(converter.find(key)!=converter.end()){
        float rate=converter[key];
        float result=rate*amount;
        cout << amount << " " << fromCurrency << " = " << result << " " << toCurrency << endl;
    }else {
            cout << "Conversion rate not found.\n";
        }      
}
};
 
 int main() {

 currency c;
    char choice;

    do {
        c.convert();
        cout << "\nDo you want to convert again? (y/n): ";
        cin >> choice;
    } while (choice == 'y' || choice == 'Y');

    cout << "Thank you for using the Currency Converter.\n";
    return 0;
}
 
 

No comments:

Post a Comment

list in c#

  using System ; using System . Collections . Generic ; class Program {     static void Main () {         // Write your C# code here  ...