나는 만든다

계산 게임

Binaural 2014. 3. 29. 18:14

Arithmetic.exe


  숫자 계산을 빨리 하고 싶다고 생각하고 있었던 중, 우연히 '수학의 제왕'이라는 어플을 접했다. 아쉬운 면도 있었지만 쓸 만한 어플인 것 같았다. 나도 계산 능력 향상을 위한 프로그램을 만들어 볼 수 있을 것 같아서 작성해 보았다. 




#include <iostream>

#include <stdlib.h>

#include <time.h>

using namespace std;

int main()

{

    int select=0;

    cout<<"덧셈: 1 입력"<<endl<<"뺄셈: 2 입력"<<endl;

    cin>>select; 

    if(select==1)

    {    

        int w=1;

        int cnt=0; 

        int time1=time(0);

        while(w==1)

        {

            int sum1, sum2, sum3, answer;

            srand(time(0));

            sum1=rand()%100;

            sum2=rand()%100;

            printf("%9d\n +%7d\n-----------\n       ",sum1,sum2);

            cin>>answer;

            cout<<endl;

            sum3=sum1+sum2;

            if(answer==sum3)

            {

                w=1;

                cnt++;

            } 

            else

            {

                break;

            }

            if(cnt==20)

            {

                cout<<"You've solved all the questions"<<endl;

                cout<<"Total caculation time: "<<time(0)-time1<<" seconds"<<endl;

                break;

            }

        }

    }

    

    if(select==2)

    {

        int w=1;

        int cnt=0; 

        int time1=time(0);

        while(w==1)

        {

            int sub1, sub2, sub3, answer;

            srand(time(0));

            sub1=rand()%100;

            sub2=rand()%100;

            if(sub2>sub1)

            {

                printf("%9d\n -%7d\n-----------\n       ",sub2,sub1);

                cin>>answer;

                cout<<endl;

                sub3=sub2-sub1;

            }

            else

            {

                printf("%9d\n -%7d\n-----------\n       ",sub1,sub2);

                cin>>answer;

                cout<<endl;

                sub3=sub1-sub2;

            }

            if(answer==sub3)

            {

                w=1;

                cnt++;

            } 

            else

            {

                break;

            }

            if(cnt==20)

            {

                cout<<"You've solved all the questions."<<endl;

                cout<<"Total caculation time: "<<time(0)-time1<<" seconds"<<endl;

                break;

            }

        }

    }

    system("PAUSE");

}