- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main(){
- float t1,t2,pass;
- int x,y,answer,answer_c;
- srand(time(NULL));
- re:
- while(true){
- x=rand()%48+51;
- y=rand()%48+51;
- answer_c=x+y;
- cout<<x<<"+"<<y<<"=";
- t1=clock();
- cin>>answer;
- t2=clock();
- pass=(t2-t1)/1000;
- if(answer==answer_c){
- cout<<"答對了!本題花"<<pass<<"秒思考"<<endl;
- break;
- }
- else {
- cout<<"答錯了!本題花"<<pass<<"秒思考"<<endl;
- break;
- }
- }
- system ("pause");
- goto re;
- return 0;
- }
複製代碼 |