0
cout << "The sum is " <<sum<<endl<<"The sumCheck is "<<sumCheck<<endl;
	if (sum==sumCheck)
	{
		cout<<"Is a polygon"<<endl;
	}
	else
	{
		cout<<"Is not a polygon"<<endl;
	}

The sum is correctly displayed as 360 and sumCheck is correctly displayed as 360 yet the message "Is not a polygon" is displayed.

I can't figure out why the "Is not a polygon" message is always displayed.

Thanks in advance for any help!

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by dinners
0

Two floating or double values are rarely equal. You have to test for a range -- maybe within 0.001 tolerance.

if ABS(val1 - val2) > 0.001)  // check if close to equal

Edited by WaltP: n/a

0
if ABS(val1 - val2) [B]>[/B] 0.001)  // check if close to equal

Shouldn't that be a less-than?

Edited by Fbody: n/a

0

Thanks for your help! The problem was what you said, that they were not exactly equal.

What I used in the end was: if ((sum-sumCheck<0.00001)||(sumCheck-sum<0.00001)) as sum could be either greater or less than sumCheck.

Thanks again!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.