程序代码:
#include <math.h>
#include <stdio.h>
#include <conio.h>
int 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);/*可以修改输入,会更好*/
getchar();
printf("please enter your answer:");
scanf("%f",&result);
getchar();
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都不循环,怎么搞的*/
return 0;
}
大家不要攻击我,我就是休息下。