哥哥,这个你真搞定了,那你是真厉害!
#include <math.h> #include <stdio.h>
main()
{
float num1,num2,result;
char answer,fuhao;
int right;
clrscr();/*清平*/
printf("*********welcome to lin er ming's system*********");
printf("\n");
do
{
printf("please enter num1,fuhao,num2:");
scanf("%f,%c,%f",&num1,&fuhao,&num2);/*可以修改输入,会更好*/
printf("please enter your answer:");
scanf("%f",&result);
switch(fuhao)
{
case '+':if(result==(num1+num2)) right=1;
else
right=0;
break;
case '-':if(result==(num1-num2)) right=1;
else
right=0;
break;
case '*':if(result==(num1*num2)) right=1;
else
right=0;
break;
case '/':if(num2==0) printf("\ninput wrong! ben ben,ha ha!!");
else
{
if(result==(num1/num2)) right=1;
else
right=0;
}
break;
}
if(right)
printf("\nyou are ringht!");
else
printf("\nplease try again!");
printf("\ndo you want togo on?(please choose 'y'or'n')");
scanf("%c",&answer);
}while((answer=='y')||(answer=='Y'));/*这个时候输入y或者Y都不循环,怎么搞的*/
}
/* 各位哥哥姐姐,我吧answer给成char型了,不过在运行到scanf("%c",&answer);
它并不跳入输入界面我观测answer发现,scanf("%c",&answer);
不能让answer赋值,直接用answer='y'就行了,大家看看怎么才能让scanf("%c",&answer);
可以赋值给answer*//*我又发现程序运行后会自己赋值\n给answer*/