first of all, sorry for my bad english.
my professor gave us a problem.
I've got to use 'struct' in solving the problem.
I need to make a program that calculates the area of square, triangle, circle and rectangle . I've done this problem. Now i need to compare the areas and show where is +-1 . Example : I introduce 49 for Area of square. I introduce 48 area of rectangle. (a= Area of square, b=Area of rectangle)
if (a>b+1)
if (a<b+1)
{cout>>"Area of square = Area of rectangle +-1";};
else
{cout>>"Area of square is higher/lower than area of rectangle +-1";};
My problem is when i introduce the values. if i introduce 100 at area of square and 10 at area of rectangle it shows me that area of square = area of rectangle +-1.
The condition in the last line of your code if (a>b+1,a<b-1) is not the same as what you have at the top:
1 2 3 4 5
if (a>b+1)
if (a<b+1)
{cout>>"Area of square = Area of rectangle +-1";};
else
{cout>>"Area of square is higher/lower than area of rectangle +-1";};
but neither are very sensible. From the problem description it sounds like you want:
1 2 3 4
if( a>b+1 || a<b+1 )// use logical or ( || )
cout>>"Area of square is higher/lower than area of rectangle +-1";
else
cout << "The areas are <= one unit apart";
This: if (a>b+1,a<b-1) will only act on the value of the last condition a<b-1