JunjieGoGoGo
2021-09-27 12:25
采纳率: 100%
浏览 25

简单的C语言语法,怎么循环?

#我想问一下要怎么修改才能让程序循环,我这个是 输入数字月份,会输出一个对应的英文缩写月份,但是一次只能输出一个,我想要让他输入完一个月份按下回车键后可以输入下一个月份要怎么弄?


```c
#include<stdio.h>
void menu()
{
    printf("---------请输入月份---------\n");
    
}
int main()
{
    int months;
    menu();
    scanf_s("%d",&months);
    switch (months)
    {
    case 1:
        printf("Jan.\n");
        break;
    case 2:
        printf("Feb.\n");
        break;
    case 3:
        printf("Mar.\n");
        break;
    case 4:
        printf("Apr.\n");
        break;
    case 5:
        printf("May.\n");
        break;
    case 6:
        printf("Jun.\n");
        break;
    case 7:
        printf("Jul.\n");
        break;
    case 8:
        printf("Aug.\n");
        break;
    case 9:
        printf("Sept.\n");
        break;
    case 10:
        printf("Oct.\n");
        break;
    case 11:
        printf("Nov.\n");
        break;
    case 12:
        printf("Dec.\n");
            break;
    default: printf("输入错误!\n");
    }
    return 0;


}

```

  • 好问题 提建议
  • 收藏

1条回答 默认 最新

  • qfl_sdu 2021-09-27 12:38
    已采纳

    如下:

    #include<stdio.h>
    void menu()
    {
        printf("---------请输入月份---------\n");
    
    }
    int main()
    {
        int months;
        char op;
        menu();
        while(1)
        {
            scanf_s("%d",&months);
            switch (months)
            {
            case 1:
                printf("Jan.\n");
                break;
            case 2:
                printf("Feb.\n");
                break;
            case 3:
                printf("Mar.\n");
                break;
            case 4:
                printf("Apr.\n");
                break;
            case 5:
                printf("May.\n");
                break;
            case 6:
                printf("Jun.\n");
                break;
            case 7:
                printf("Jul.\n");
                break;
            case 8:
                printf("Aug.\n");
                break;
            case 9:
                printf("Sept.\n");
                break;
            case 10:
                printf("Oct.\n");
                break;
            case 11:
                printf("Nov.\n");
                break;
            case 12:
                printf("Dec.\n");
                break;
            default: printf("输入错误!\n");
            }
    
    
            printf("是否继续(Y/N)?");
            op = getchar();
            if(op == 'N' || op == 'n')
                break;
        }
        
    
        return 0;
    }
    
    
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题