为什么我的C程序停止运行?

时间:2014-10-01 11:40:25

标签: c switch-statement

#include <stdio.h>
#include <stdlib.h>

int main(void){
    int lumens;
    int watts;

    printf("please enter Watts\n");
    scanf("%d",watts);

    switch (watts) {
        case 15:
            lumens=125;
            printf("%d\n", lumens);
            break;
        case 25:
            lumens=215;
            printf("%d\n", lumens);
            break;
        case 40:
            lumens=500;
            printf("%d\n", lumens);
            break;
        case 60:
            lumens=880;
            printf("%d\n", lumens);
            break;
        case 75:
            lumens=1000;
            printf("%d\n", lumens);
            break;
        case 100:
            lumens=1675;
            printf("%d\n", lumens);
            break;
        default:
            lumens=(-1);
            printf("%d\n", lumens);
    }

    return 0;
}
对我来说,好像它没有运行switch语句?但我不明白

3 个答案:

答案 0 :(得分:2)

scanf应该是

printf("please enter Watts\n");
scanf("%d",&watts);

答案 1 :(得分:2)

&中使用scanf

      scanf("%d",&watts);

答案 2 :(得分:0)

指示内存位置存储值的位置:&watts表示存储值的内存位置。

scanf("%d",&watts);