我正在学习C语言,但我无法运行“C&C”。继续该计划

时间:2016-09-18 07:20:20

标签: c

在这里我得到了元音的答案,但不是继续它说继续错误和休息时间。

#include < stdio.h >
  main() {
    char c, d;
    printf("say your word to find the vowels\n");
    scanf("%c", & c);
    if (c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U')
      printf("you got a vowel\n");
    else
      printf("cool no vowel word\n");
    printf("continue\n");
    printf("(y/n)\n");
    scanf("%c", & d);
    if (d == 'y' || d == 'Y')
      continue;
    else
      break;
    return 0;
  }

2 个答案:

答案 0 :(得分:2)

if (d == 'y' || d == 'Y')
  continue;  // where?
else
  break;     // what?

您的主要功能中没有continuebreak

continuebreak只在循环中有意义,因此您应该在while(true)中的代码周围添加main()循环,以重复整个事情直到用户决定退出。

答案 1 :(得分:0)

在循环块中继续并中断...但是在这里你还没有将它们添加到循环中。将整个if块放在while(1)中,它将起作用

#include <stdio.h>

int main()
{
    char c;
    int d;
    while (1) {
        printf("say your word to find the vowels\n");
        scanf("%c", &c);

        if (c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U')
            printf("you got a vowel\n");
        else
            printf("cool no vowel word\n");

        printf("To continue enter 1\n");
        scanf("%d", &d);

        if (d == 1)
            continue;
        else
            break;
    }  
    return 0;
}

检查以下链接中的continue和break语句语法。

https://www.codingunit.com/c-tutorial-for-loop-while-loop-break-and-continue