Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#中查找BMI指数值和体重状态?_C# - Fatal编程技术网

如何在C#中查找BMI指数值和体重状态?

如何在C#中查找BMI指数值和体重状态?,c#,C#,我们想为BMI指数值编写一个程序,但没有成功。这是我的密码 int under = 0, nor = 0, over = 0, obes = 0; int m, h; //MASS & HEIGHT Console.Write("Please enter the mass in lbs :"); m = Convert.ToInt32(Console.ReadLine()); Console.Write("Please enter the height in

我们想为BMI指数值编写一个程序,但没有成功。这是我的密码

int under = 0, nor = 0, over = 0, obes = 0;
int m, h; //MASS & HEIGHT
Console.Write("Please enter the mass in lbs :");
m = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the height in inches :");
h = Convert.ToInt32(Console.ReadLine());
int[, ] arr = new int[2, 20]; //2 dimensional array
Console.Write("HEIGHT :  ");
for (int i = 0; i < 1; i++) {
  for (int j = 0; j < 19; j++) {
    arr[i, j] = h++;
    Console.Write(arr[i, j] + " ");
  }
}
for (int i = 0; i < 1; i++) {
  for (int j = 0; j < 19; j++)
    arr[i + 1, j] = m++;
}

Console.WriteLine();
Console.Write("         ________");
Console.WriteLine("");
Console.WriteLine("MASS(lbs)");
Console.Write(arr[1, 0] + "      |");
for (int i = 0; i < 1; i++) {
  for (int j = 0; j < 19; j++) {
    int ibs = arr[1, 0] * 703 / (arr[i, j] * arr[i, j]); //FORMULA IBS
    if (ibs < 18.5) {
      under++;
      ibs = -1122;
      Console.Write(ibs + " ");
    } else if (ibs < 24.5) {
      nor++;
      Console.Write(ibs + " ");
    } else if (ibs < 29.9) {
      over++;
      ibs = 1122;
      Console.Write(ibs + " ");
    } else if (ibs > 30) {
      obes++;
      ibs = 0;
      Console.Write(ibs + " ");
    }
  }
}
Console.WriteLine("");
Console.WriteLine("TOTAL UNDERWEIGHT ARE:" + under);
Console.WriteLine("TOTAL NORMAL ARE :" + nor);
Console.WriteLine("TOTAL OVERWEIGHT ARE :" + over);
Console.WriteLine("TOTAL OBESE ARE :" + obes);
            
这个for循环:
for(inti=0;i<1;i++)
只循环一次,i等于0。因此,在构建
arr
时,您不需要这些。事实上,您可以组合这两个初始化循环

for (int j = 0; j < 20; j++) // note the j<20: I don't want to miss the highest index, 19.
{
    arr[0, j] = h++; // heights in row 0
    arr[1, j] = m++; // masses in row 1
    Console.Write(arr[0, j] + " ");
}

for(int j=0;j<20;j++)//注意jYou“没有成功”,但是发生了什么?您的结果是什么,它们与预期有什么不同?只有一个输入是170,我认为我的编程循环逻辑不正确@HansKesting即质量(lbs)170 | 0 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122你没有控制台。为sir@HansKesting写作我编辑了上面的代码,但问题仍然没有解决。是的,我忘记了公式外的循环
MASS(lbs) 
170 |0 0 0 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 -1122 -1122 -1122 -1122 -1122 -1122 -1122 -1122 -1122 -1122
for (int j = 0; j < 20; j++) // note the j<20: I don't want to miss the highest index, 19.
{
    arr[0, j] = h++; // heights in row 0
    arr[1, j] = m++; // masses in row 1
    Console.Write(arr[0, j] + " ");
}
Console.Write("MASS(lbs)");
for (int i = 0; i < 20; i++) // *all* values in row 0
{
    // start a new line, with a mass-header
    Console.WriteLine();
    Console.Write(arr[1, i] + "      |");
    for (int j = 0; j < 20; j++)
    {
        int ibs = arr[1, i] * 703 / (arr[0, j] * arr[0, j]); //FORMULA IBS
        // etc