Okay I am on a debian linux system using Code:Blocks ide. I'm trying to make a simple Currency converter (USD to CDN & vice versa) that runs on a console. I set the exchange rate to be 1.0188 (CDN(x) * 1.0188), but when I run the program it converts it like it's only multiplying by 1 not 1.0188. How can I get my program to multiply it by 1.0188 not 1. and show a value rounded up to 2 decimal points.
Here's what I have so far. Please note that I'm planning to make this look neater by moving the functions CDNtoUSD and USDtoCDN(currently print2) to another .cpp file and make a header file.
#include <iostream>
#include <iomanip>
usingnamespace std;
int CDNtoUSD(int x, int y)
{
return x * y;
}
void print2() //Declaration of print2. This will eventually becom USDtoCDN
{
cout << "print2 start";
}
int main()
{
int n;
cout << "Type 1 for CDN to USD" << endl; //Giving a choice between CDNtoUSD and print2
cout <<"Type 2 for print2: ";
cin >> n;
if (n == 1)
{
int x; //Amount in CDN entered
int y;
y = 1.0188; //Exchange rate
cout << "please enter amount: ";
cin >> x;
cout << x << "=" << CDNtoUSD(x , y);
}
elseif (n == 2)
print2();
return 0;
}
EDIT: okay I changed the x and y in CDNtoUSD to float. and the x and y in main() to float as well. but how do I get it to show an answer rounded up in 2 digits after the decimal point.