scanf(" %c",&replay);//" %c"有空格的问题
#include "stdafx.h"
#include <stdio.h>
void main()
{
float opr1,opr2;//定义两个操作数
char op;//定义运算符
char replay;//定义终止符
do
{
printf("Input the expression:\n");
scanf("%f%c%f",&opr1,&op,&opr2);
switch(op)
{
case '+':
printf("%2.2f + %2.2f = %2.2f\n",opr1,opr2,opr1+opr2);
break;
case '-':
printf("%2.2f - %2.2f = %2.2f\n",opr1,opr2,opr1-opr2);
break;
case '*':
printf("%2.2f * %2.2f = %2.2f\n",opr1,opr2,opr1*opr2);
break;
case '/':
if(0 == opr2)
printf("Denominator is zeor!\n");
else
printf("%2.2f ÷ %2.2f = %2.2f\n",opr1,opr2,opr1/opr2);
break;
default:
printf("Unknow operator!\n");
break;
}
printf("Do you want to continue? 'Y/N'or'y/n'\n");
//replay = getch();
scanf(" %c",&replay);//" %c"有空格
}while((replay == 'Y')||(replay == 'y'));
}
我没有弄明白为什么scanf(" %c",&replay);加了空格后就把(replay == 'Y')||(replay == 'y')的功能真正实现了。求各位大侠指点!