<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    選擇java 進入自由開放的國度

    隨筆 - 49, 文章 - 3, 評論 - 154, 引用 - 1
    數據加載中……

    C++猜數字游戲

    /*-----------------------------------------------------------
      猜數字游戲
      C++中數組的運用,條件語句,賦值語句,循環語句等元素的應用
    -----------------------------------------------------------*/

    #include <iostream>
    #include <string>

    using namespace std;

    const int seq_size = 18;
    const int max_seq  = 6;
    const int max_tries = 3;  

    string seq_names[max_seq] = {
      "Fibonacci",
      "Lucas",
      "Pell",
      "Triangular",
      "Square",
      "Pentagonal"
    };

    int elem_seq[ seq_size ] = {
       1, 2, 3,   //Fibonacci
       3, 4, 7,   //lucas
       2, 5, 12,  //Pell
       3, 6, 10,  //Triangular
       4, 9, 16,  //Square
       5, 12, 22  //Pentagonal
    };

    int usr_val;          //the value user inputed
    int num_total;        //total times
    int num_tries = 0;    //the try number
    int num_rights = 0;    //the right times
    int cur_tuple = 0;    //the location pointer of current array

    double usr_score;     //user's score
    char usr_rsp;        //try again?


    bool go_for_it = true; //try again
    bool next_seq  = true; //display the next number
    bool got_it    = false;//right or error?


    int main(){
     while ( next_seq && cur_tuple < seq_size) {
       //display the array
          cout << " the First two elements of the sequence are: "
         << elem_seq[ cur_tuple ] << ", "
         << elem_seq[ cur_tuple + 1]
         << " in the "
         << seq_names[ cur_tuple/3]
         << "  sequence.\n"
         << "What is the next element?";
        
      //初始化,進入循環,判斷是否正確
      got_it    = false;
      go_for_it = true;
            num_tries = 0;
      while ((!got_it) && (go_for_it)) {
         int usr_guess;
         cin >> usr_guess;
         num_tries++;
        
         if (usr_guess == elem_seq[ cur_tuple + 2]){
           //答對了
        cout << "Congratulations! you are right! \n";
        got_it = true;
           num_rights++;
         }
         else{
           //猜錯了
        //告訴用戶是錯的,詢問是否愿意再試一次
          switch (num_tries){
          case 1 :
           cout << "Oops! Nice guess but not quite it.\n";
           break;
          case 2 :
           cout << "Hmm, Sorry, wront a second time. \n";
           break;
          case 3 :
           cout << "Ah, this is harder than it looks, isn't it?\n";
           go_for_it = false; //跳出
           break;
          default :
           cout << "It must be getting pretty frustrating by now! \n";
           break;
          }//switch
          if (num_tries < 3) cout << "Do you try it again? (Y|N)" ;
          cin  >> usr_rsp;
                   if (usr_rsp == 'N' || usr_rsp == 'n')
           go_for_it = false;
         }//if
            }//small while
      
      cout << "Want to try another sequence? (Y/N)";
      char try_again;
      cin >> try_again;
      if (try_again == 'N' || try_again == 'n')
       next_seq = false;
      
      cur_tuple += 3;             //指到下一個數列
      num_total += num_tries;     //總數
     };//large while
     
      //輸出得分,簡單統計信息
     cout << "---------------------------- \n"
       << "the total : " << num_total
       << "the right times: " << num_rights << "\n"
       << "---------------------------- \n";
      return 0;
    }

    posted on 2005-12-23 16:15 soochow_hhb 以java論成敗 以架構論英雄 閱讀(809) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 破了亲妺妺的处免费视频国产| 亚洲国产香蕉碰碰人人| 亚洲最大在线视频| a级毛片免费在线观看| 亚洲一区无码精品色| 乱淫片免费影院观看| 亚洲&#228;v永久无码精品天堂久久 | 无码精品人妻一区二区三区免费| 免费鲁丝片一级在线观看| 亚洲熟妇无码av另类vr影视| 毛片基地免费视频a| 亚洲国产成人手机在线观看| 激情无码亚洲一区二区三区| 天天摸天天碰成人免费视频| 亚洲成a∧人片在线观看无码| 国产男女猛烈无遮档免费视频网站| 日韩亚洲翔田千里在线| 亚洲VA综合VA国产产VA中| 亚洲色欲或者高潮影院| 久九九精品免费视频| 亚洲AV无码一区二区乱子仑| 亚洲XX00视频| 特级无码毛片免费视频尤物 | 亚洲一级黄色大片| 女人18毛片a级毛片免费视频| 久久亚洲精品11p| 国产亚洲情侣一区二区无| 免费人成网站在线观看不卡| 免费又黄又爽又猛的毛片| 一级毛片在播放免费| 91情国产l精品国产亚洲区| 成人免费午夜在线观看| 人禽伦免费交视频播放| 亚洲精品视频在线| 午夜电影免费观看| 91福利免费网站在线观看| 一本色道久久综合亚洲精品蜜桃冫| 亚洲日韩在线第一页| 免费观看激色视频网站bd| 美女无遮挡免费视频网站| 老司机亚洲精品影院|