V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
noobhacker
V2EX  ›  问与答

关于一个简单 C 程序的出错提问。

  •  
  •   noobhacker · Jul 29, 2016 · 1332 views
    This topic created in 3566 days ago, the information mentioned may be changed or developed.
    你好,我想请问一个问题。我抄了一串 C 程序的代码,是关于星期几查询系统的,代码如下。
    #include <stdio.h>
    int main(void)
    {
    int weekday = 3;
    switch (weekday)
    {
    case1:
    printf("today is Monday!\n");
    break;
    case2:
    printf("today is Tuseday!\n");
    break;
    case3:
    printf("today is Wednesday!\n");
    break;
    case4:
    printf("today is Thursday!\n");
    break;
    case5:
    printf("today is Friday!\n");
    break;
    case6:
    printf("today is Saturday!\n");
    break;
    case7:
    printf("today is Sunday!\n");
    break;
    default:
    printf("You write the wrong Number!");
    break;
    }
    return 0;

    }
    我在开始的时候赋值为 3 ,但最后调试的时候却显示了 default 的输出结果,我不知道问题出在哪里了。
    4 replies    2016-07-30 10:31:26 +08:00
    noark9
        1
    noark9  
       Jul 29, 2016
    我的结果正常-,-
    noobhacker
        2
    noobhacker  
    OP
       Jul 29, 2016
    @noark9 你是直接复制黏贴的吗
    noark9
        3
    noark9  
       Jul 29, 2016
    @noobhacker 是的,以及在 case 和 case 后面的数字之间加了个空格
    noobhacker
        4
    noobhacker  
    OP
       Jul 30, 2016
    @noark9 多谢 是要加个空格的!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2515 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 06:49 · PVG 14:49 · LAX 23:49 · JFK 02:49
    ♥ Do have faith in what you're doing.