我剛剛進入了一個開關案例代碼..我不明白爲什麼當我按'1',它仍然會默認情況下總是。初學者切換案例行動總是默認
#include <stdio.h>
int main() {
char c = 0;
int x = 0, y = 0;
printf("Please write 2 numbers:\n");
scanf("%d %d", &x, &y);
printf("Please choose an action from the math menu:\n\n1.add\n2.sub\n");
scanf(" %c", &c);
switch (c)
{
case 1:
printf("%d + %d is %d\n", x, y, x+y);
break;
default: printf("Wrong value\n");
break;
}
return 0;
}
嘗試''案例49''。 「案例1」實際上是由SOH角色觸發的。請參閱[this](http://www.asciitable.com/) – Thevenin
或簡單地'case'1'' –
case'1' - genious – MoZZ