'C++ API realtime currency conversion
I'm working on a school project for a currency converter with 5 currencies, and I'm having trouble figuring out how to get value from a website xe like the Philippine peso to USD. I know I can just get the value from the website and set it in an array or int, but I want it to be a Realtime conversion of the currency itself. Is there a way to do that, and if so, how?
I only have 2 day to finish this project of mine because my professor gave us only a little bit of time
this is the code that I've got for now
#include <iostream>
#include <string>
using namespace std;
int picked[5] = {0,0,0,0,0};
int main()
{
string currentvalue[5][5] = {{"1","2","3","4","5"},{"6","7","8","9","10"},{"11","12","13","14","15"},{"16","17","18","19","20"},{"21","22","23","24","25"}};
string currency[5] = {"Philippine Peso","euro","pounds","yen","usd"};
int yourcurrency;
int convert;
int timesToRun = 5;
int number = 1;
cout << "Choose your currency \n" << endl;
for (int counter = 0 ; counter < timesToRun; counter++)
{
cout << number;
cout << "." + currency[counter] << endl;
number++;
}
cout << "\nOption: ";
cin >> yourcurrency;
system("CLS");
yourcurrency = yourcurrency - 1;
picked[yourcurrency] = 1;
cout << "Select your currency you want to convert into \n" << endl;
number = 1;
for (int counter = 0; counter < timesToRun; counter++)
{
if (picked[counter] != 1){
cout << number;
cout << "." + currency[counter] << endl;
number++;
}
}
cout << "\nOption: ";
cin >> convert;
if (convert > yourcurrency ){
convert;
}
system("CLS");
cout << currency[yourcurrency]+ " - " + currency[convert];
cout << " [" + currentvalue[yourcurrency][convert] + "] " << endl;
cout << "Amount: ";
int cash;
cin >> cash;
int value = stoi(currentvalue[yourcurrency][convert]);
int total = cash * value;
cout << currency[convert]<< ": " << total;
}
Solution 1:[1]
If I understand your question, here is the document that explains how to get data from xe.com website: https://www.xe.com/xecurrencydata/XE_Currency_Data_API_Specifications.pdf
Here is a free alternative (up to 250 requests per month) https://exchangeratesapi.io/
Solution 2:[2]
When I see using namespace std; and system("CLS"), I guess you are very early beginning C++ developer. This task may be difficult at this level.
Look at the menus on the site you reference. There is "Business & API" -> Xe Currency Data API.
- Register and start your free trial. You will get trial authentication tokens.
- Use any http client, for example cpp-httplib, for retrieving actual data using the API.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vlad Feinstein |
| Solution 2 | 273K |
