How to make a divsion comparison

I am building a small math game and i am having trouble with the division portion of the game.

ex.
float a,b,answer,trueAnswer;
cout<<"enter values"
cin>>a>>b;
cout<<"enter answer";
cin>>answer;
trueAnswer=a/b;

if(trueAnser==answer)
cout<<"correct";
else
cout<<"wrong, the correct answer is "<<trueAnswer;

my issues is:
why does the float variable trueAnswer rounds numbers of after 4 decimal places and sometimes it rounds of after 5. This makes it impossible to compare trueAnswer and answer
Because your PC cannot represent every floating point number. It simply cannot. It has to approximate.

http://floating-point-gui.de/
you could use integers and multiply them to get trueanswer
Topic archived. No new replies allowed.