计算可装入卡车后部的箱子数量

时间:2014-05-18 20:03:45

标签: javascript math

此代码计算可装入卡车后部的方框数量。所有维度都是用户定义的,答案四舍五入到最接近的整数。我想让程序考虑计算中方框的方向。我怎么能这样做?

这是我目前的代码:

<!DOCTYPE html>
<html>
<body>
<script>

  //////////////////////////    
 // Zachary Holmes ICS3U //
//////////////////////////

// This program determines the number of boxes that can fit into a truck

// Declaring box size in centimetres
var boxHeightCm = prompt("What is the height of your box in centimetres?");
var boxWidthCm = prompt("What is the width of your box in centimetres?");
var boxLengthCm = prompt("What is the length of your box in centimetres?");

// Declaring truck size in metres
var truckHeight = prompt("What is the height of your truck in metres?");
var truckWidth = prompt("What is the width of your truck in metres?");
var truckLength = prompt("What is the length of your truck in metres?");

// Converting box size to metres
var boxHeight = boxHeightCm / 100;
var boxWidth = boxWidthCm / 100;
var boxLength = boxLengthCm / 100;

// Declaring variables used in equation
var boxVolume = boxHeight * boxWidth * boxLength;
var truckVolume = truckHeight * truckWidth * truckLength;

// Calculations
var boxNumberUnrounded = truckVolume / boxVolume;
var boxNumber = boxNumberUnrounded.toFixed(0);

// Output answer
alert(boxNumber);

</script>
</html>

2 个答案:

答案 0 :(得分:0)

您希望我们做作业吗?

计算每个方向可堆叠的框数(除以尺寸,截断),然后将这三个数相乘以计算总框数。不要使用卷。

答案 1 :(得分:0)