where have you defined 'm'?
And do you think you are subtracting k once the division is done or subtracting k from your denominator before the division is carried out?
also note that something like 1.17 might actually be something like 1.17000000001, or something like that. shouldn't affect a calculation like this though.
I accidently took it out while copying code here, i was deleting some off-topic lines :P. A bit more code here, and I need to get n=0.1, but instead im getting 0.18, or 0.2, probably because of rounding problem.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <iomanip>
#include <cmath>
usingnamespace std;
int main()
{
double s=10, // money you have in your x currency
k=1.16, // money item costs in other y currency
ge=1.73, // return in y currency
n, // loss because of convertations
m; // random number ;p
m=s/3.4825-k;
n=ge-m;
cout << setprecision(1) << n;
return 0;
}
Also, im diving s/3.4825 to convert it to other currency.
You could probably pull it off with some combination of setprecision and round. Note the several functions found near the bottom of the round reference. trunc() would probably be what you're looking for.
Return Value
The value of x rounded to the nearest integral (as a floating-point value).
that's the problem with round
Often with money, any calculation generally is carried to at least 4 decimal places and then displayed at 2 places (obvious). This has cropped many times in the recent past and an easy way to display the 2 places for x is cout<< (float)((int)( x * 100 ) / 100 );