- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int x, y, ans, ans_c;
- long t1,t2,pass;
- while(true)
- {
- x=rand()%49+51; //51~99
- y=rand()%49+51;
- ans_c=x+y;
- cout<<x<<" + "<<y<<" = ";
- t1=clock();
- cin>>ans;
- t2=clock();
- pass=t2-t1;
- if(ans==ans_c)
- cout<<"答對了! 本題花了"<<pass<<"毫秒思考!"<<endl;
- else
- cout<<"答錯了! 本題花了"<<pass<<"毫秒思考!"<<endl;
- cout<<endl;
- }
- system("pause");
- return 0;
- }
複製代碼 |