I want to check in my if and else if statement if the inputs form a square or a rectangle, now my if and else if statements seems to be unreadable, now I'm thinking of ways to improve it.
/* input are angles in degrees, 1st side is parallel to 3rd side, 2nd side is parallel to 4th side*/
static void Main(string[] args)
{
Console.Write("Input first: ");
int first = int.Parse(Console.ReadLine());
Console.Write("Input second: ");
int second = int.Parse(Console.ReadLine());
Console.Write("Input third: ");
int third = int.Parse(Console.ReadLine());
Console.Write("Input fourth: ");
int fourth = int.Parse(Console.ReadLine());
// all sides are equal
// logic for if and else-if, needs codereview for improvement
if (first == second && first == third && first == fourth && second == third && second == fourth && third == fourth)
{
Console.WriteLine("Square");
}
else if (first != second && first == third && first != fourth && second != third && second == fourth )
{
Console.WriteLine("Rectangle");
}
else
{
Console.WriteLine("Not a square nor a rectangle");
}
Console.ReadKey();
}
first
a length or an angle measure? If angles, the code lacks info to distinguish square from rectangle. \$\endgroup\$first
is a length, the code lacks info to distinguish square from rhombus. \$\endgroup\$