Any questions?
Reply Back New Topic
View Topic

哪里错了呢?

2132 浏览:343 回复:2 赞:0 Started by Qiancheng 6 months ago

#include <stdio.h>
int main()
{
    int a,b,n;
    char x;
    scanf("%d%d%s",&a,&b,&x);
    if ((b==0)&&(x=='/'))
        printf("Divided by zero!");
    else if ((x=='+')||(x=='-')||(x=='*')||(x=='/'))
    {
        switch(x)
        {
            case '+':n=a+b;break;
            case '-':n=a-b;break;
            case '*':n=a*b;break;
            case '/':n=a/b;break;
        }
        printf("%d",&n);
    }
    else if ((x!='+')||(x!='-')||(x!='*')||(x!='/'))
        printf("Invalid opearar!");
    return 0;
}
View Replies

Replied by xaero 6 months ago 赞:2

输入问题,x是char,你用%s。由于%c不会跳空格,输两次试试:

scanf("%d%d%c%c",&a,&b,&x,&x);

Replied by xaero 6 months ago 赞:5

cin也就不会有这个问题了