用某些回应打破案例

用某些回应打破案例

我正在创建一个小的评分程序,并与这个案件有困难。当我输入一个“E”时,它会像默认建议那样正确地中断,但是它通过第一个开关语句运行,然后退出程序。
只有当我输入字母“e”时才会发生这种情况。如果我输入“Q”或其他什么东西,它就不会退出?

case 'd': // Field Competition Logs
{
  int fieldRound;

  int ifaaField[2], ifaaFieldTotal;
  int ifaaHunter[2], ifaaHunterTotal;
  int fitaField[1];
  int field3D[1];

  printf ("Please select the type of round you shot\n\n");
  printf ("\t(a) IFAA Field\n\t(b) IFAA Hunter\n\t(c) Fita Field\n\t(d) 3D Field\n> ");
  scanf (" %d", &fieldRound);

  switch (fieldRound)
  {
    case 'a': // Ifaa Field Round
    {
      printf ("Please enter the score for your first round > ");
      scanf (" %d", &ifaaField[0]);

      printf ("Please enter the score for your second round > ");
      scanf (" %d", &ifaaField[1]);

      ifaaFieldTotal = ifaaField[0] + ifaaField[1];

      printf ("Total of your first half (%d) and your second half (%d) is %d", ifaaField[0], ifaaField[1], ifaaFieldTotal);

      break;
    }

    case 'b': // Ifaa Hunter Round
    {
      printf ("Please enter the score for your first round > ");
      scanf (" %d", &ifaaHunter[0]);

      printf ("Please enter the score for your second round > ");
      scanf (" %d", &ifaaHunter[1]);

      ifaaHunterTotal = ifaaHunter[0] + ifaaHunter[1];

      printf ("Total of your first half (%d) and your second half (%d) is %d", ifaaHunter[0], ifaaHunter[1], ifaaHunterTotal);

      break;
    }

    case 'c': // Fita Field Round
    {
      printf ("Please enter your Fita Field score > ");
      scanf (" %d", &fitaField[0]);

      printf ("Total of your Fita Field round is %d", fitaField[0]);

      break;
    }

    case 'd': // Field 3D Round
    {
      printf ("Please enter your 3D Field score > ");
      scanf (" %d", &field3D[0]);

      printf ("Total of your 3D Field round is %d", field3D[0]);

      break;
    }

    default:
    printf ("Please enter a valid response");
    break;
  }

  break; // Breaks out of Case D

}

case 'e': // Exits the program
{
  printf ("Thank you, Good bye!\n");
  return 0;
}

输出
Please select the type of round you shot

    (a) IFAA Field
    (b) IFAA Hunter
    (c) Fita Field
    (d) 3D Field
> e
Please enter a valid response
Hi s. c, Please choose from the following options by typing the letter and pressing the 'return' key

    (a) Enter Scored Practice logs
    (b) Enter Practice Arrow count
    (c) Enter Competition logs
    (d) Enter Field Competition Logs
    (e) Exit Program
> Thank you, Good bye!

最佳答案

        scanf (" %d", &fieldRound);

这个scanf失败了!它需要数字输入,而不是字母字符!

关于c - 用某些回应打破案例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33363192/

10-12 16:14