为什么scanf("%c", &g);这句话不运行啊?
153查看
1回复
2019-02-09T16:00:09+08:00
交流讨论

include <stdio.h>

int main (void) { double num1; double num2; char oper; char g;

do{    
    printf("请输入需要计算的算式:\n");
    scanf("%lf%c%lf", &num1, &oper, &num2);

    switch(oper)
    {
        case '+': 
            printf("= %lf\n", num1+num2);
            break;
        case '-':
            printf("= %lf\n", num1-num2);
            break;
        case '*':
            printf("= %lf\n", num1*num2);
            break;    
        case '/':
            if (num2 == 0)
                printf("输入错误!\n"); 
            printf("= %lf\n", num1/num2);
            break;    
        case '%':
            if ((long)num2 == 0)
                printf("输入错误!\n");
            printf("= %ld\n", (long)num1%(long)num2);
            break;    
        default:
            printf("输入错误!\n");
            break;            
    }

    printf("是否继续执行此程序?(Y/N):");
    scanf("%c", &g);


}while ('y' == g ||'Y' == g);

return 0;

}

全部回复

在 printf("是否继续执行此程序?(Y/N):"); 前面加一句 getchar();

2019-02-11T20:31:05+08:00
回复
你的回复