本帖最後由 陳柏霖 於 2019-4-2 20:28 編輯
- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- int x;
- cout<<"***超級金頭腦 v1.0***"<<endl;
- cout<<"遊戲規則: 電腦隨機出題, 比賽誰能在最短的時間內做完!"<<endl;
- system("pause");
- system("cls");
-
- cout<<"有幾位挑戰者?";
- cin>>x;
- system("cls");
-
- string name[x];
- double done[x];
- srand(time(NULL));
-
- for(int i=0; i<x; i++)
- {
- cout<<"第"<<i+1<<"位挑戰者你好, 請輸入你的大名:";
- cin>>name[i];
- system("pause");
- system("cls");
-
- cout<<name[i]<<"同學請就位!"<<endl;
- system("pause");
- system("cls");
-
- int yes=0;
- while(yes<3)
- {
- int a=rand()%889+111,
- b=rand()%889+111;
- double star, end, pass;
-
- int ans;
- star=clock();
- cout<<a<<"+"<<b<<"=";
- cin>>ans;
- end=clock();
- pass=end-star;
-
-
- if(ans==a+b)
- {
- cout<<"答對了!本題花了"<<pass<<"毫秒"<<endl;
- done[i]=done[i]+pass;
- yes++;
- }else
- {
- cout<<"答錯了!正確答案是"<<a+b<<",本題花了"<<pass<<"毫秒"<<endl;
- done[i]=done[i]+pass;
- }
-
- }
- cout<<endl<<endl;
- cout<<name[i]<<"同學總共花了"<<done[i]<<"毫秒"<<endl;
-
- system("pause");
- system("cls");
- }
- system("pause");
- return 0;
- }
複製代碼 |