首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

scanf(" %c"&replay);//" %c"有空格的有关问题

2012-12-14 
scanf( %c,&replay)// %c有空格的问题#include stdafx.h#include stdio.hvoid main(){float opr1

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')的功能真正实现了。求各位大侠指点!

热点排行