Hi I am wondering if there is good way to compare a "double" value up to some decimal places! For example here is my code:
else if (choice == 2)
{
srand(seed);
firstVal = (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;
secondVal = (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;
ans = firstVal / secondVal; //this part!
cout << "Generating Values..";
pause(3);
cout << endl;
cout << firstVal << endl;
cout << secondVal << endl;
cout << "Please enter the division of two Values(top value / bottom): ";
cin >> userAns;
if (userAns == ans) //This part!!
cout << "Congraturation. You got right answer" << endl;
else
cout << "Wrong dummy!" << endl;
}
I have tested some numbers. They works if there is no remainder but when it comes to decimal places, how should I compare the values???? for example if the answer comes out to be irrational number like 3.979797979797....