«

随机出5道算术题

点亮灯 发布于 阅读:78 C++


来算题.rar

#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std ;
int main()
{
int xx ,a,b;
int shu1,shu2;
int daan1,daan2;
//**************************************************************//

cout<<"**********************"<<endl;
cout<<"***____-来算题-____***"<<endl;
cout<<"**********************"<<endl;
cout<<"***     1-加法     ***"<<endl;
cout<<"***     2-减法     ***"<<endl;
cout<<"***     3-乘法     ***"<<endl;
cout<<"***     4-除法     ***"<<endl;
cout<<"**********************"<<endl;

//**************************************************************//
cout<<"选择(1-4):";
cin>>xx;
srand(time(0));

//**************************************************************//
switch(xx){
//**************************************************************//
    case 1:
        cout<<"已选择1-加法"<<endl<<"开始做题;"<<endl;
        for(int i=1;i<=5;i++)
        {
        shu1 = rand() % (1000 - 1 + 1) + 1;
        shu2 = rand() % (1000 - 1 + 1) + 1;
      cout<<"第"<<i<<"题:"<<endl<<shu1<<"+"<<shu2<<"=";
     daan1 =shu1+shu2;
      cin>>daan2;

    if(daan1==daan2)
    {
  cout<<"答案对了!"<<endl;
  a++;
    }
    else
    {
         cout<<"答案错了!"<<endl;
    }
        }
  cout<<"共答对"<<a<<"道";

   break;
//**************************************************************//
    case 2:
        cout<<"已选择2-减法"<<endl<<"开始做题;"<<endl;
        for(int i=1;i<=5;i++)
        {
        shu1 = rand() % (1000 - 1 + 1) + 1;
        shu2 = rand() % (1000 - 1 + 1) + 1;
      cout<<"第"<<i<<"题:"<<endl<<shu1<<"-"<<shu2<<"=";
     daan1 =shu1-shu2;
      cin>>daan2;

    if(daan1==daan2)
    {
  cout<<"答案对了!"<<endl;
  a++;
    }
    else
    {
         cout<<"答案错了!"<<endl;
    }
        }
  cout<<"共答对"<<a<<"道";

   break;
//**************************************************************//
    case 3:
        cout<<"已选择3-乘法"<<endl<<"开始做题;"<<endl;
        for(int i=1;i<=5;i++)
        {
        shu1 = rand() % (15 - 1 + 1) + 1;
        shu2 = rand() % (15 - 1 + 1) + 1;
      cout<<"第"<<i<<"题:"<<endl<<shu1<<"*"<<shu2<<"=";
     daan1 =shu1*shu2;
      cin>>daan2;

    if(daan1==daan2)
    {
  cout<<"答案对了!"<<endl;
  a++;
    }
    else
    {
         cout<<"答案错了!"<<endl;
    }
        }
  cout<<"共答对"<<a<<"道";
   break;
//**************************************************************//
    case 4:

        cout<<"已选择4-除法"<<endl<<"开始做题;"<<endl;

        for(int i=1;i<=5;i++)
        {

        shu1 = rand() % (100 - 1 + 1) + 1;
        shu2 = rand() % (100 - 1 + 1) + 1;

      cout<<"\n第"<<i<<"题:"<<shu1*shu2<<"/"<<shu1<<"=";

      cin>>daan2;

    if(daan2==shu2)
    {
  cout<<"答案对了!"<<endl;
  a++;
    }
    else
    {
         cout<<"答案错了!"<<endl;
    }
        }
  cout<<"共答对"<<a<<"道";
   break;
    default:
        cout<<"错误!!!!!!!!!!";
  }
}