Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.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语言编程,开关箱问题 #包括 内部主(空) { char ch; //字符=ch printf(“请键入字符[a-Z或a-Z]('x'退出):”; scanf(“%c”和“ch”); switch(ch)//switch语句 { 案例“a”: printf(“%c是元音。\n”,ch); 打破 案例“e”: printf(“%c是元音。\n”,ch); 打破 案例“i”: printf(“%c是元音。\n”,ch); 打破 案例“o”: printf(“%c是元音。\n”,ch); 打破 案例“u”: printf(“%c是元音。\n”,ch); 打破 案例“A”: printf(“%c是元音。\n”,ch); 打破 案例“E”: printf(“%c是元音。\n”,ch); 打破 案例“I”: printf(“%c是元音。\n”,ch); 打破 案例“O”: printf(“%c是元音。\n”,ch); 打破 案例“U”: printf(“%c是元音。\n”,ch); 打破 违约: 如果(ch!=“x”){ printf(“%c是辅音。\n”,ch); 中断;} else if(ch='x'){ printf(“%c是辅音。\n”,ch); 中断;} }_C_Switch Statement - Fatal编程技术网

用C语言编程,开关箱问题 #包括 内部主(空) { char ch; //字符=ch printf(“请键入字符[a-Z或a-Z]('x'退出):”; scanf(“%c”和“ch”); switch(ch)//switch语句 { 案例“a”: printf(“%c是元音。\n”,ch); 打破 案例“e”: printf(“%c是元音。\n”,ch); 打破 案例“i”: printf(“%c是元音。\n”,ch); 打破 案例“o”: printf(“%c是元音。\n”,ch); 打破 案例“u”: printf(“%c是元音。\n”,ch); 打破 案例“A”: printf(“%c是元音。\n”,ch); 打破 案例“E”: printf(“%c是元音。\n”,ch); 打破 案例“I”: printf(“%c是元音。\n”,ch); 打破 案例“O”: printf(“%c是元音。\n”,ch); 打破 案例“U”: printf(“%c是元音。\n”,ch); 打破 违约: 如果(ch!=“x”){ printf(“%c是辅音。\n”,ch); 中断;} else if(ch='x'){ printf(“%c是辅音。\n”,ch); 中断;} }

用C语言编程,开关箱问题 #包括 内部主(空) { char ch; //字符=ch printf(“请键入字符[a-Z或a-Z]('x'退出):”; scanf(“%c”和“ch”); switch(ch)//switch语句 { 案例“a”: printf(“%c是元音。\n”,ch); 打破 案例“e”: printf(“%c是元音。\n”,ch); 打破 案例“i”: printf(“%c是元音。\n”,ch); 打破 案例“o”: printf(“%c是元音。\n”,ch); 打破 案例“u”: printf(“%c是元音。\n”,ch); 打破 案例“A”: printf(“%c是元音。\n”,ch); 打破 案例“E”: printf(“%c是元音。\n”,ch); 打破 案例“I”: printf(“%c是元音。\n”,ch); 打破 案例“O”: printf(“%c是元音。\n”,ch); 打破 案例“U”: printf(“%c是元音。\n”,ch); 打破 违约: 如果(ch!=“x”){ printf(“%c是辅音。\n”,ch); 中断;} else if(ch='x'){ printf(“%c是辅音。\n”,ch); 中断;} },c,switch-statement,C,Switch Statement,我在这段代码上遇到了很多麻烦。我的代码非常完美,但是它需要不断重复,直到输入“x”。尝试了一个while循环,没有任何运气,最近刚刚尝试了默认的if语句,这也不起作用。如果有人能给我一点启示,我非常接近 您不需要重复太多。您可以为给定的案例使用多个标签: #include <stdio.h> int main(void) { char ch; //character = ch printf("Please type a character [A-Z or a-

我在这段代码上遇到了很多麻烦。我的代码非常完美,但是它需要不断重复,直到输入“x”。尝试了一个while循环,没有任何运气,最近刚刚尝试了默认的if语句,这也不起作用。如果有人能给我一点启示,我非常接近

  • 您不需要重复太多。您可以为给定的案例使用多个标签:

    #include <stdio.h>
    int main(void)
    {
    char ch;
    //character = ch        
        printf("Please type a character [A-Z or a-z] ('x'to exit):");
        scanf("%c", &ch);   
            switch(ch) //switch statement
            {
            case 'a':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'e':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'i':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'o':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'u':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'A':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'E':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'I':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'O':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'U': 
                printf("%c is a vowel.\n", ch);
                    break; 
            default:
                if(ch != 'x'){
                    printf("%c is a consonant.\n", ch); 
                        break; }
                else if(ch == 'x'){
                    printf("%c is a consonant.\n", ch);
                        break; }
            }   
    
  • 您确实需要一个循环:

    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
    case 'A':
    case 'E':
    case 'I':
    case 'O':
    case 'U':
        printf("%c is a vowel.\n", ch);
        break;
    default:
        printf("%c is a consonant.\n", ch);
        break;
    
  • 在执行
    开关之前,您可能需要在那里添加一个
    isalpha
    调用

  • 您不需要重复太多。您可以为给定的案例使用多个标签:

    #include <stdio.h>
    int main(void)
    {
    char ch;
    //character = ch        
        printf("Please type a character [A-Z or a-z] ('x'to exit):");
        scanf("%c", &ch);   
            switch(ch) //switch statement
            {
            case 'a':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'e':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'i':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'o':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'u':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'A':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'E':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'I':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'O':
                printf("%c is a vowel.\n", ch);
                    break; 
            case 'U': 
                printf("%c is a vowel.\n", ch);
                    break; 
            default:
                if(ch != 'x'){
                    printf("%c is a consonant.\n", ch); 
                        break; }
                else if(ch == 'x'){
                    printf("%c is a consonant.\n", ch);
                        break; }
            }   
    
  • 您确实需要一个循环:

    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
    case 'A':
    case 'E':
    case 'I':
    case 'O':
    case 'U':
        printf("%c is a vowel.\n", ch);
        break;
    default:
        printf("%c is a consonant.\n", ch);
        break;
    
  • 在执行
    开关之前,您可能需要在那里添加一个
    isalpha
    调用

  • 或者你可以做一个功能菜单的方法

    while(ch != 'x'){
      ...
    
      ...
    }
    
    我会看看@Carl Norum的代码优化答案

    或者你可以做一个功能菜单的方法

    while(ch != 'x'){
      ...
    
      ...
    }
    

    我想看看@Carl Norum的代码优化答案!

    向我们展示您的while循环实现,这就是您应该做的!(除非您想使用函数)
    while
    循环,或者可能是
    do
    -
    while
    循环,将是正确的方法。您说您在while循环中没有任何运气;如果不看到您的代码并知道它是如何失败的,我们无法帮助您。您可以使用
    while
    循环更新显示版本的问题吗?此外,您可以组合多个cases:
    case'a
    :case'e':case'i':…`您不能在
    开关中使用
    中断
    来中断封闭循环。您应该真正检查
    scanf()的返回值
    以确保您获得了所需的字符。我怀疑换行符是代码中的辅音。您可以通过使用
    %c”
    (在
    %
    前面有一个空格)作为格式字符串来修复此问题。您可能需要添加一个空格
    scanf(“%c”,&ch);
    使用上一个函数。向我们展示您的while循环实现,这就是您应该如何执行的!(除非您想使用函数)
    while
    循环,或者可能是
    do
    -
    while
    循环,将是正确的方法。您说您在while循环中没有任何运气;如果不看到您的代码并知道它是如何失败的,我们无法帮助您。您可以使用
    while
    循环更新显示版本的问题吗?此外,您可以组合多个cases:
    case'a
    :case'e':case'i':…`您不能在
    开关中使用
    中断
    来中断封闭循环。您应该真正检查
    scanf()的返回值
    以确保您获得了所需的字符。我怀疑换行符是代码中的辅音。您可以通过使用
    %c”
    (在
    %
    前面有一个空格)作为格式字符串来修复此问题。您可能需要添加一个空格
    scanf(“%c”,&ch);
    以使用上一个字符。