Hello.I am trying to calculate the number of drywall sheets needed to cover a specific wall area.Each sheet is 4x8=32 and the wall area will be calculated based on the user's input (length and height).
If the wall area could be divided by 32 without any remainder, there would be no problem. It simply would be wallArea / 32. Of course, this is not the case usually.
How can I create a simple if-else statement which will take into account the remainder of the above calculation?
I know that the remainder can be calculated like this:
float getMod = (int)(getHeight * getLength) % 32;
And I also need to take into account the outcome of the calculation (getMod > 0) but I'm stuck.
Ehm, why are you calculating with 32?
The user enteres height=32, length=1, the wallArea is 32, but no sheet will cover that.
I'm just interested, maybe i get the exercise wrong.
But when you want to store the integer-part of the calculation and the mod separately, you can do it like this:
1 2 3
int val = hight * length;
int whole = (int) (val / 32);
int mod = (val % 32);
example:
case 1: val = 32 -> whole=1, mod = 0
case 2: val = 40 -> whole = 1, mod = 8
just use if (mod == 0) {... to find out if your in case 1 or 2.
Thanks for your reply but I solved the problem. 32 is the area of a drywall sheet. Even if the input was 1x32 the drywall installer would need one sheet of drywall - he would just have to cut it.