noobhacker
V2EX  ›  问与答

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

  •  
  •   noobhacker · Jul 29, 2016 · 1752 views
    This topic created in 3761 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
    noark9
    Jul 29, 2016
    1
    我的结果正常-,-
    noobhacker
    noobhacker
    OP
    Jul 29, 2016
    2
    @noark9 你是直接复制黏贴的吗
    noark9
    noark9
    Jul 29, 2016
    3
    @noobhacker 是的,以及在 case 和 case 后面的数字之间加了个空格
    noobhacker
    noobhacker
    OP
    Jul 30, 2016
    4
    @noark9 多谢 是要加个空格的!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1682 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 00:58 · PVG 08:58 · LAX 16:58 · JFK 19:58
    ♥ Do have faith in what you're doing.