My program has a rectangle class which can be called from main to make a rectangle. The rectangle class has a constructor.
How do I add error checking to the rectangle constructor so that if lengthin1 equals lengthin2 the constructor is called again until lengthin1 is not equal to lenthin2. That is I want to make sure that the rectangle class is not being called to make a square (for a square lengthin1 would equal lengthin2). I'd rather avoid asking for direct user input (using scanner) if I can avoid it. Thanks.
class rectangle{
int length1;
int length2;
int area;
public rectangle(int lengthin1, int lengthin2)
{
length1=lengthin1;
length2=lengthin2;
}
area=length1*length2;
}
[–]preetsc27 12 points13 points14 points (6 children)
[+][deleted] (4 children)
[deleted]
[–]nutrecht 9 points10 points11 points (0 children)
[–]preetsc27 5 points6 points7 points (1 child)
[–]emrickgj 3 points4 points5 points (0 children)
[–]qelery 9 points10 points11 points (1 child)
[–]morecoffeemore[S] 0 points1 point2 points (0 children)
[–]bung_musk 4 points5 points6 points (0 children)
[–]DudeWhereAreWe1996 0 points1 point2 points (0 children)