#include
int main(void)
{
float data1,data2;
char op;
char reply;
do{
printf("Please enter the expression:\n");
scanf("%f %c%f",&data1,&op,&data2);//%c前有一空格
switch(op)
case "+":printf("%f+%f=%f\n",data1,data2,data1+data2);break;
case "-":printf("%f-%f=%f\n",data1,data2,data1-data2);break;
case "*":printf("%f*%f=%f\n",data1,data2,data1*data2);break;
case "/":if(fabs(data2)
printf("Division by zero!\n");
}
else
printf("%f/%f=%f\n",data1,data2,data1/data2);
break;
default:printf("Unknown operator!\n");
printf("Do you want to continue(Y/N or y/n?)");
scanf(" %c",&reply);//%c前有一空格
while(reply=="Y"||reply=="y");
printf("Program is over!\n");
return 0;
注意一定要有空格,否則程式無法正常執行
#include
#include
int main(void)
{
float data1,data2;
char op;
char reply;
do{
printf("Please enter the expression:\n");
scanf("%f %c%f",&data1,&op,&data2);//%c前有一空格
switch(op)
{
case "+":printf("%f+%f=%f\n",data1,data2,data1+data2);break;
case "-":printf("%f-%f=%f\n",data1,data2,data1-data2);break;
case "*":printf("%f*%f=%f\n",data1,data2,data1*data2);break;
case "/":if(fabs(data2)
{
printf("Division by zero!\n");
}
else
{
printf("%f/%f=%f\n",data1,data2,data1/data2);
}
break;
default:printf("Unknown operator!\n");
}
printf("Do you want to continue(Y/N or y/n?)");
scanf(" %c",&reply);//%c前有一空格
}
while(reply=="Y"||reply=="y");
printf("Program is over!\n");
return 0;
}
注意一定要有空格,否則程式無法正常執行