这是我的代码块,我不知道如何让周长和体积执行计算。例如,当我为前 4 个参数输入 1,1,1,1 时,我得到 0, 0 表示体积和周长。
if (packages == 1)
{
int width = 0, length = 0, height = 0, weight = 0;
int volume = 0, girth = 0;
int[] packageInfo = new int[6] { width, length, height, weight ,volume, girth };
packageInfo[4] = height * width * length;
packageInfo[5] = (2 * length + 2 * width);
double packageSum = 0;
for (int k = 0; k < 4; k++)
{
string line = Console.ReadLine();
if (!int.TryParse(line, out packageInfo[k]))
{
Console.WriteLine("Couldn't parse {0} - please enter integers", line);
k--;
}
}
if(packageInfo[3] > 25)
{
packageSum = 0;
Console.WriteLine("Package couldn't be shipped because of its size.");
}
if (volume > 4800)
{
packageSum = packageSum + 5.95;
}
if (volume > 9600)
{
packageSum = 0;
Console.WriteLine("Package couldn't be shipped because of its size.");
}
foreach (var item in packageInfo)
Console.WriteLine(item.ToString());
}