Lab problem

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.


And that's my program :

#include <iostream.h>
#include <math.h>
#include <stdio.h>
struct triunghi
{float a,b,c,s;};
struct cerc
{float r,p;};
struct dreptunghi
{float L,l;};
struct patrat
{float lP;};
int main()
{triunghi tr; cerc cr; dreptunghi dr; patrat pt;
float a,b,c,d;
cout<<"a="; cin>>tr.a; cout<<"b="; cin>>tr.b; cout<<"c="; cin>>tr.c;
cout<<"Laturile triunghiului : "<<tr.a<<" "<<tr.b<<" "<<tr.c;
cout<<endl;
tr.s=(tr.a+tr.b+tr.c)/3;
cout<<"Semiperimetrul triunghiului este : "<<tr.s;
cout<<endl;
d=sqrt(tr.s+tr.s*tr.a+tr.s*tr.b+tr.s*tr.c);
cout<<"Aria triunghiului este : "<<d;
cout<<endl;
cout<<"Raza cercului : ";
cin>>cr.r;
cr.p=3.14;
c=cr.p*cr.r*cr.r;
cout<<"Aria cercului este "<<c<<endl;
cout<<"Lungimea dreptunghiului : "; cin>>dr.L; cout<<"Latimea dreptunghiului : "; cin>>dr.l;
b=dr.L*dr.l;
cout<<"Aria dreptunghiului este : "<<b<<endl;
cout<<"Latura patrat :";
cin>>pt.lP;
a=pt.lP*pt.lP;
cout<<"Aria patratului este : "<<a<<endl;
if (a>b+1,a<b-1)

can you continue?
closed account (D80DSL3A)
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
Topic archived. No new replies allowed.