四则运算

#include<stdio.h>
int right=0,wrong=0;
void jia()
{
 int a,b,c;
 a=rand()%100;
 b=rand()%100;
 printf("%d+%d=",a,b);
 scanf("%d",&c);
 if(a+b!=c){printf("回答错误\n");wrong++;}
 else{printf("回答正确\n");right++;}
}
void jian()
{
 int a,b,c;
 a=rand()%100;
 b=rand()%100;
 printf("%d-%d=",a,b);
 scanf("%d",&c);
 if(a-b!=c){printf("回答错误\n");wrong++;}
 else{printf("回答正确\n");right++;}
}
void sheng()
{
 int a,b,c;
 a=rand()%100;
 b=rand()%100;
 printf("%d*%d=",a,b);
 scanf("%d",&c);
 if(a*b!=c){printf("回答错误\n");wrong++;}
 else{printf("回答正确\n");right++;}
}
void chu()
{
 int a,b,c;
 a=rand()%100;
 b=rand()%100;
 printf("%d/%d=",a,b);
 scanf("%d",&c);
 if(a/b!=c){printf("回答错误\n");wrong++;}
 else{printf("回答正确\n");right++;}
}
void main()
{
 int n,i=0;
 while(1)
 {
  printf("\n\n选择(1)加,选择(2)减,选择(3)剩,选择(4)除\n");
  if(i==0)scanf("%d",&n);
  switch(n)
  {
   case 1:jia();break;    
   case 2:jian();break;
   case 3:sheng();break;    
   case 4:chu();break;
  }
  printf("输入1继续此算法,输入2重新选择算法,输入3退出并打印成绩\n");
  scanf("%d",&i);
  if(i==1)i=1;
  if(i==2)i=0;
  if(i==3)break;
 }
 printf("总共做了%d题,正确%d题,错误%d题\n",right+wrong,right,wrong);
}

posted @ 2015-03-27 22:40  38郑胜斌  阅读(243)  评论(1编辑  收藏  举报