小学算术题

来源:互联网 发布:位置虚拟定位软件 编辑:程序博客网 时间:2024/04/29 07:17
#include <iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(0));
    int i,right=0,result,amount=1,m,n;
    int x,y;


    for(i=1;i<=10;i++)
    {
        
        x=rand()%100;
        y=rand()%100+1;
        cout<<"第"<<amount<<"题: ";

        m=x%4;
        if(x<y)
        {
            n=x;
            x=y;
            y=n;
        }
        if(m==0)
        {
           cout<<x<<"+"<<y<<"=";
           cin>>result;
           if(result==(x+y))
  {
                cout<<"right"<<endl;
right++;
  }
            else
               cout<<"wrong"<<endl;
        }
        else if(m==1)
        {
           cout<<x<<"-"<<y<<"=";
           cin>>result;
           if(result==(x-y))
  {
                cout<<"right"<<endl;
right++;
  }
            else
                cout<<"wrong"<<endl;
        }
        else if(m==2)
        {
           cout<<x<<"*"<<y<<"=";
           cin>>result;
           if(result==(x*y))
  {
                cout<<"right"<<endl;
right++;
  }
            else
                cout<<"wrong"<<endl;
        }
        else if(m==3)
        {
           int yushu;
           cout<<x<<"/"<<y<<"=";
           cin>>result>> yushu;
           if(result==(x/y)&&yushu==(x%y))
  {
                cout<<"right"<<endl;
right++;
  }
            else
               cout<<"wrong"<<endl;
        }
        amount++;
    }
    cout<<"正确"<<right<<"道题,最终得分为"<<10*right;
    return 0;
}

0 0