小学生算数システム

1520 ワード

/*copyright (c) 2013,         
 *All rights reserved.
 *  :  
 *    :2013 11 18 
 *   :v1.0
*/
#include <iostream>
#include<ctime>
#include<cstdlib>
int qa(); //    ,               ,   1,   0
using namespace std;
int main()
{
    int sum=0;//    
    for(int i=0; i<10; i++)
    {
        cout<<" "<<i+1<<" :"<<endl;
        sum+=qa();
        cout<<endl;
    }
    cout<<"    "<<sum<<"  ,  "<<sum*10<<endl;
    return 0;
}

int qa()
{
    srand(time(0)); //       
    int a,b,c,d,t;
    a=rand()%100+1;
    b=rand()%100+1;
    c=rand()%4;
    if(a<b&&(c==1||c==3)) //      ,               (       ,       )
    {
        d=a;
        a=b;
        b=d;
    }
    if(c==3)//    ,     ,      (       ,       )
        a=(a/b)*b;
    switch(c)
    {
    case 0:
        d=a+b;
        cout<<a<<"+"<<b<<"=";
        break;
    case 1:

        d=a-b;
        cout<<a<<"—"<<b<<"=";
        break;
    case 2:
        d=a*b;
        cout<<a<<"×"<<b<<"=";
        break;
    case 3:
        d=a/b;
        cout<<a<<"÷"<<b<<"=";
        break;
    }
    cin>>t;
    if(t==d)
        cout<<"    right! ";
    else
        cout<<"    wrong! ";
    return t==d;
}

実行結果: