首页 > 解决方案 > 不想打印多条语句

问题描述

当打印语句“不是字母表中的字母”时,我不希望我的代码打印其他语句。请帮忙!我还是个菜鸟。

#include <stdio.h>

int main()
{
    char ch;
    int int_ch;

    do {

        printf("Type in an alphabet letter:");
        scanf("%c%*c", &ch);

        int_ch = (int)ch;
        printf("Ch has ascii value %d\n", ch);

        if ((ch >= 'a') && (ch <= 'z'))
        {
            int_ch = int_ch - 32;
        }
        else if ((ch >= 'A') && (ch <= 'Z'))
        {
            int_ch = int_ch + 32;
        }
        else
        {
            printf("Is not a letter of the Alphabet.");
        }

        //THIS HERE

        ch = (char)int_ch;

        printf("Ch is now %c\n", ch);
        printf("Ch is now ascii value %d\n", int_ch);

    } while (ch != '#');

    return (0);
}

标签: cif-statement

解决方案


添加continue是这个else-statement

            else
            {
                printf("Is not a letter of the Alphabet.");
                continue;
            }

continue语句跳过循环的当前迭代并继续下一次迭代。


推荐阅读