rectangle

how to check the if rectangle is a square or not?

Check if the side lengths are the same.
All it's sides have equal length.
that i know but how to do the coding for that
if (width==height) cout << "square\n";
How do you define your rectangle?
Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
int main{
std::cout << ("Enter side 1: ") << std:endl;
std::cin >> s1;
std::cout << ("Enter side 2: ") << std:endl;
std::cin >> s2;
std::cout << ("Enter side 3: ") << std:endl;
std::cin >> s3;
std::cout << ("Enter side 4: ") << std:endl;
std::cin >> s4;
if((s1 | s2) ==  ( s3 | s4)) //Check a pair of sides are congruent.
{
std::cout << ("It's a square!") << std::endl;
}
else
{
std::cout << ("It's a rectangle!") << std::endl;
}
return(0);
}
deleted:]
Last edited on
A square is a rectangle but a rectangle is not necessary a square.
What kind of rectangle?
Are you using a 2D graphic engine?
Or is it just a console app?
And do you know the coordinates of the rectangle and the width/height of it?
Topic archived. No new replies allowed.