随机数的加减乘除四则运算(可继续,选择,退出)

#include "stdio.h"
#include"windows.h"
int right=0,wrong=0;
void add()
{
  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 minu()
{
  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 mul()
{
  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 di()
{
  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 choise,con=0;
   
   printf("\n\n\t\t随机数的四则运算\n"); 
   system("pause");
   system("cls");
   while(1)
   {
    printf("\n\n\t\t请选择:\n加(输入1)\n减(输入2)\n乘(输入3)\n除(输入4)\n"); 
    if(con==0)scanf("%d",&choise);
    switch(choise)
    {
     case 1:add();break;
     case 2:minu();break;
     case 3:mul();break;
     case 4:di();break;
    }
    printf("是否继续或者重新选择运算或者退出程序?\n继续(输入1),重新(输入2),退出(输入3)");
    scanf("%d",&con);
    if(con==1)con=1;
    if(con==2)con=0;
    if(con==3)break;
   }
   printf("您总做了%d个题,正确%d道,错误%d道!\n",right+wrong,right,wrong);
   system("pause");
} 


 

转载于:https://www.cnblogs.com/qijun1120/p/9752147.html

你可能感兴趣的:(随机数的加减乘除四则运算(可继续,选择,退出))