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

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

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

    選擇java 進(jìn)入自由開(kāi)放的國(guó)度

    隨筆 - 49, 文章 - 3, 評(píng)論 - 154, 引用 - 1
    數(shù)據(jù)加載中……

    C++猜數(shù)字游戲

    /*-----------------------------------------------------------
      猜數(shù)字游戲
      C++中數(shù)組的運(yùn)用,條件語(yǔ)句,賦值語(yǔ)句,循環(huán)語(yǔ)句等元素的應(yīng)用
    -----------------------------------------------------------*/

    #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?";
        
      //初始化,進(jìn)入循環(huán),判斷是否正確
      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]){
           //答對(duì)了
        cout << "Congratulations! you are right! \n";
        got_it = true;
           num_rights++;
         }
         else{
           //猜錯(cuò)了
        //告訴用戶是錯(cuò)的,詢問(wèn)是否愿意再試一次
          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;             //指到下一個(gè)數(shù)列
      num_total += num_tries;     //總數(shù)
     };//large while
     
      //輸出得分,簡(jiǎn)單統(tǒng)計(jì)信息
     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論成敗 以架構(gòu)論英雄 閱讀(807) 評(píng)論(0)  編輯  收藏


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 国产中文字幕免费| 中文字幕免费视频精品一| 亚洲av麻豆aⅴ无码电影| 一区二区三区在线免费| 亚洲精品午夜在线观看| 久久国产免费观看精品| 亚洲人精品亚洲人成在线| 亚洲人成影院在线观看| 成人精品综合免费视频| 一区国严二区亚洲三区| 精品国产免费一区二区三区香蕉 | 亚洲色在线无码国产精品不卡| 免费一级毛片女人图片| 香蕉97碰碰视频免费| 亚洲AV无码成人专区片在线观看| 成人免费午夜在线观看| CAOPORN国产精品免费视频| a级亚洲片精品久久久久久久 | 18女人腿打开无遮掩免费| 最新亚洲人成无码网站| 亚洲美女在线观看播放| 69堂人成无码免费视频果冻传媒| 老司机午夜免费视频| 亚洲人成www在线播放| 久久被窝电影亚洲爽爽爽| 免费看的成人yellow视频| 99视频免费播放| www免费插插视频| 亚洲av无码成人精品区一本二本 | 国产亚洲大尺度无码无码专线| 成全高清视频免费观看| 57pao国产成视频免费播放 | 国内免费高清在线观看| 午夜精品免费在线观看| 国产黄在线观看免费观看不卡| 亚洲中文无码永久免| 99亚洲精品高清一二区| 国产亚洲精品自在久久| 亚洲精品视频免费观看| 国产人妖ts在线观看免费视频| 无码日韩人妻av一区免费|