- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- srand(time(NULL));
-
- int a,b;
- int my_ans,ans;
- a=rand()%49+51;
- b=rand()%49+51;
- ans=a+b;
- cout<<a<<"+"<<b<<"=";
-
- long start,end,pass;
- start=clock();
- cin>>my_ans;
- end=clock();
- pass=end-start;
-
- if(ans==my_ans)
- cout<<"答對了! 花了"<<pass<<"毫秒";
- else
- cout<<"答錯了! 花了"<<pass<<"毫秒";
- cout<<endl;
-
- system("pause");
- return 0;
- }
複製代碼 |