+ 3
Help me out, this solution is utterly confusing!!đ
Please help explain to me why the 60 feet of duct tape wasn't converted to inches when the area of the door was actually converted in the Duct Tape Code coach (c++). Here's the solution: int main() { int width, height; cin >> width >> height; double roll, door; door = width * height * 12 * 2; roll = 60 * 2; cout << ceil(door/roll); return 0;
2 RĂ©ponses
+ 6
DevAbdul
The code is badly written, when working with inches only, it's:
door = w * 12 * h * 12 * 2;
it's square inches value. therefore:
roll = 60 * 12 * 2;
But because those values will get devided, you can simplify that as:
door = w * h * 12 * 2;
roll = 60 * 2;
This is source of your confusion.
However you can simplify that more and therefore the solution can be written as:
door = w * h * 12 ;
roll = 60 ;
more:
door = w * h ;
roll = 5;
door = w * h; // in square feets
roll = 5; // half a roll in square feets
this is also confusing. So if you want to do it in square inches, you can write like the first code. Also you can calculate area of a roll in square feets (sq. in /144 = sq.ft). so:
60 * 12 * 2 = 1440/144 = 10
then do both in square feets:
door = w * h * 2; // door area (2 sides)
roll = 10; // area of every tape roll
All of the codes above give same result, but there's a huge difference in readability of those.
0
Well, that's better. Thanks Tinađ