help of this program

hi i want help for explain of this program

you are reuired to write two functions which,given two values for the width and height of rectsangle ,would output the area and perimeter of the rectangle.Hοwever,depending on whether the width and hight are egual or not ,different massages should be displayed indicating whether it is a rectangle or a sguere.


area=width*height

perimeter=2*(width+height)

please help :(
Last edited on
simple, calculate the area and perimeter the same and have an if to check equality of width and height (if equal cout<<"Square"; if unequal cout<<"Rectangle";) hope it helps
So this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>

using namespace std;

float area(float,float);
float per(float,float);

int main()
{
	float len,wid;
	
	cout<<"Enter the length of your rectangle: ";
	cin>>len;
	cout<<"\nEnter the width: ";
	cin>>wid;
	if(len==wid)
	 cout<<"\nThis is a square!";
        else
         cout<<"\nIt is a rectangle!";
        cin.ignore();
	cin.get();
	system("CLS");
	cout<<"Area: "<<area(len,wid)<<endl;
	cout<<"Perimeter: "<<per(len,wid)<<endl;
	cin.get();
	return 0;
}

float area(float a,float b)
{
	return (a*b);
}

float per(float a,float b)
{
	return (2*(a+b));
}
Last edited on
thanks for the answer.
Topic archived. No new replies allowed.