Heidip @ 2022-10-02 09:48:01
WA里说的是第一行错了但是我不知道错在哪求各位帮忙看看谢谢了
#include<stdio.h>
int main()
{
int x,y;
char z;
scanf("%d%d%c",&x,&y,&z);
if(z=='+')printf("%d",x+y);
else if(z=='-')printf("%d",x-y);
else if(z=='*')printf("%d",x*y);
else if(z=='/')
{
if(y==0)
{
printf("Divided by zero");
}
else
{
printf("%d",x/y);
}
}
else
{
printf("Invalid operator");
}
}
by sy107 @ 2022-10-02 09:54:51
@Heidip Divided by zero
和 Invalid operator
后面要加感叹号
by SZH0523 @ 2022-10-02 09:57:00
@Heidip
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
char c;
cin >> a >> b >> c;
if(b==0&&c=='/')
{
cout << "Divided by zero!" << endl;
return 0;
}
else if (c=='*')
cout << a * b << endl;
else if (c=='/')
cout << a / b << endl;
else if (c=='+')
cout << a + b << endl;
else if (c=='-')
cout << a - b << endl;
else
cout<<"Invalid operator!";
return 0;
}
by Heidip @ 2022-10-02 15:03:49
@SZH0523 谢谢,但我还没开始学C++