Hello, I was recently making a convertor from number in base 10 to a binary number, and I ran into this problem:
(EXAMPLE CODE OF THE ISOLATED ISSUE)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <stdio.h>
#include <math.h>
usingnamespace std;
int main()
{
int exp = 2;
int binary = 0;
cout<<pow(10,exp)<<endl; //This will cout<< the number 100.
binary += pow(10,exp);
cout<<binary; //This will cout<< the number 99...
}
The pow function will return the number 100, but when adding the function to "binary", binary will become 99. Why does this happen? Any insight would be appreciated.