c# 没有从While循环中走出来[关闭]

3yhwsihp  于 2023-11-15  发布在  C#
关注(0)|答案(1)|浏览(263)

**已关闭。**此问题需要debugging details。目前不接受答案。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
41分钟前关闭
Improve this question
我写了一个循环,我认为案例4会让我跳出循环,但不知何故,它不会。

while (menu == 1)
{
    printf("you made it.");
}

while (menu == 2)
{
    int freeSlots = calcFreeSlots(inventar, sizeInv);
    int optionsInv = optionsInvQuestion(); //returns an OptionValue for the InvMenuOptions

    switch (optionsInv)
    {
    case 1: //openInv
        printInv(inventar, sizeInv, freeSlots);
        break;

    case 2: //removeItem
        printf("Not Implemented\n");
        break;
    
    case 3: //addItem
        printf("Not Implemented\n");
        break;
        
    case 4: //exitInvMenu
        menu = 1;
        break;
    }
}

字符串
我试着问ChatGPT,它没有帮助。

rjjhvcjd

rjjhvcjd1#

假设上面截取的代码进入第二个while循环,如果optionsInv的值为4,则肯定会退出循环

#include <stdio.h>

int main() {
  int menu = 2;

  //  while (menu == 1)
  // {
  //     printf("you made it.");
  // }

  while (menu == 2) {
    // int freeSlots = calcFreeSlots(inventar, sizeInv);
    // int optionsInv = optionsInvQuestion(); //returns an OptionValue for the InvMenuOptions
    int optionsInv = 4;

    switch (optionsInv) {
    case 1: //openInv
      printf("inside case 1\n");
      // printInv(inventar, sizeInv, freeSlots);
      break;

    case 2: //removeItem
      printf("inside case 2");
      printf("Not Implemented\n");
      break;

    case 3: //addItem
      printf("inside case 3");
      printf("Not Implemented\n");
      break;

    case 4: //exitInvMenu
      printf("inside case 4\n");
      menu = 1;
      break;
    }
  }

  printf("outside loop");
  return 0;
}

字符串

输出:


的数据

相关问题