好吧我承认我吹牛了,这代码我写了62行- -
不过如果不包含前面那个超级恶心的菜单的话,应该只有四十来行……
飞燕啊……你的语法高亮有Bug啊啊啊啊……
/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http:// **
*****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#define CLS() system("cls")
#define MENU \
"***************************************************\n" \
" 小学生四则运算练习系统\n" \
"***************************************************\n" \
" 1--加法练习\n" \
" 2--减法练习\n" \
" 3--乘法练习\n" \
" 4--除法练习\n" \
" 0--退出\n" \
"请选择(0--4):"
char op[]="+-*/";
char *right[]={"你真聪明!","继续保持!","加油!"};
char *wrong[]={"再想一想,你还有两次机会。","不要着急,要把握住最后一次机会喔!","要加强练习喔!"};
int Calc(int* n1,int pn,int* n2)
{
switch (op[pn])
{
case '+':return *n1 + *n2;
case '-':return *n1 - *n2;
case '*':return *n1 * *n2;
case '/':*n2=rand()%10;*n1=*n2*(rand()%10+1);return *n1 / *n2;
}
return 0;
}
int InputNum()
{
int n;
while (scanf("%d",&n) != 1)
{
while (getchar()!='\n');
puts("对不起,请重新输入!");
}
while (getchar()!='\n');
return n;
}
int Practise(int pn)
{
int n1=rand()%100+1,n2=rand()%100+1,ans=Calc(&n1,pn,&n2),i;
printf("%d %c %d = ?\n",n1,op[pn],n2);
for (i=0;i<3 && InputNum()!=ans;i++)
printf("不正确,%s\n",wrong[i]);
if (i==3) printf("正确答案是%d.\n",ans);
else printf("正确,%s\n",right[i]);
printf("是否继续练习?(Y/N)");
return getchar()=='y';
}
int main()
{
int n;
while (CLS(),printf(MENU),(n=getchar())!='0')
if (n>='1' && n<='4')while (Practise(n-'1'));
return 0;
}
[[it] 本帖最后由 StarWing83 于 2008-6-25 14:38 编辑 [/it]]