返回列表 發帖

[專題實作] 超級金頭腦 (二)

設計遊戲 "超級金頭腦",
讓使用者計算兩個範圍介於51~99之隨機亂數的和.
參考作法如下:

1. 要有一個起始畫面, 顯示標題與遊戲規則


2. 參賽人數


3. 參賽者姓名


4. 請就位的訊息


5. 測驗中畫面


6. 排名


本帖隱藏的內容需要回復才可以瀏覽

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int player,t,allt,a=0,pat[]= {};
  8.     string name[]= {};
  9.     srand(time(NULL));
  10.     cout<<"     超級金頭腦"<<endl<<endl;
  11.     cout<<"有幾位挑戰者?";
  12.     cin>>player;
  13.     for(int r=0; r<=player-1; r++)
  14.     {
  15.         cout<<"第"<<r+1<<"位挑戰者您好,請問您的大名:";
  16.         cin>>name[r];
  17.         _sleep(500);
  18.         system("cls");
  19.         cout<<"請第"<<r+1<<"位挑戰者就位";
  20.         _sleep(500);
  21.         system("cls");
  22.         t=clock();
  23.         allt=clock();
  24.         while(a<3)
  25.         {
  26.             int q1=rand()%48+51,q2=rand()%48+51,a1;
  27.             cout<<q1<<"+"<<q2<<"=";
  28.             cin>>a1;
  29.             if(a1==q1+q2)
  30.             {
  31.                 cout<<"你答對了,總共花費"<<clock()-t<<"毫秒"<<endl;
  32.                 a++;
  33.             }
  34.             else
  35.                 cout<<"你答錯了,總共花費"<<clock()-t<<"毫秒"<<endl;
  36.             t=clock();
  37.         }
  38.         cout<<name[0]<<"總共用了"<<allt<<"毫秒";
  39.         pat[r]=allt;
  40.         a=0;
  41.     }

  42.     return 0;
  43. }
複製代碼

TOP

返回列表