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!

What data type are sum and sumCheck?

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
if ABS(val1 - val2) [B]>[/B] 0.001)  // check if close to equal

Shouldn't that be a less-than?

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.