猜數字

Home Home
引用 | 編輯 HsK
2010-11-06 01:54
樓主
推文 x0
這我參考版上再改改的

希望給一些意見 ^^


#include <iostream>
#include <stdio.h>

using namespace std;


int main( int argc, char *argv[] )
{
  printf( "\n HsK test! \n\n 猜數字遊戲 \n" );
 
  int byby = 5;
  srand((unsigned) time(NULL));  //剛更新 ^^  
  int min = 0, max = 100, round = 0, this_round = rand()%100+1;
  int player;
  std::string again;
 
  while(byby == 5)
  {          
          cout << " Max=" << max << " ; Min=" << min << " ;" << endl;
          cout << " I Guess :";
          cin >> player;
          cout << endl;
         
          if (player <= min || player >= max)
          {
                  cout << "注意!!!" << endl;
                 
                  if (player <= min)
                  player = min;
                  else if (player >= max)
                      player = max;
          }
          else ..

訪客只能看到部份內容,免費 加入會員



獻花 x1
引用 | 編輯 wa19860120
2010-11-07 13:46
1樓
  
雖然看似簡陋

但是很好玩 可以增進一些智力

謝謝大大分享 以後可能會常玩這個了

獻花 x1
引用 | 編輯 HsK
2010-11-07 16:14
2樓
  
修了第1次隨機數為42的bug ^^

獻花 x0
引用 | 編輯 T4593279
2010-11-12 17:25
3樓
  
以前常玩的小遊戲
很懷念說

獻花 x0
引用 | 編輯 csr
2011-01-28 17:22
4樓
  
很不錯的游戲
第五次就猜中
謝謝

獻花 x0
引用 | 編輯 ms042087
2011-02-27 20:21
5樓
  
C++ == 我懂VB

獻花 x0
引用 | 編輯 星辰雪
2011-02-27 21:03
6樓
  
如果你很熟悉一種語言的話
學第二,第三種
都可以學很快
你大概看一下c/c++
應該就可以大概了解
這程式麼寫的了

獻花 x0
引用 | 編輯 k7138
2011-03-23 19:32
7樓
  
感謝大大的發表

獻花 x0
引用 | 編輯 wing50kimo
2011-04-09 03:45
8樓
  
對於我這個初學者真的是獲益良多~
謝謝分享~

獻花 x0
引用 | 編輯 csr
2011-04-18 20:41
9樓
  
下面是引用 sk@.@ 於 2010-11-06 01:54 發表的 第二次試作 修了第1次隨機數為42的bug,|猜數字: 到引言文
這我參考版上再改改的
希望給一些意見 ^^
[code]#include <iostream>
#include <stdio.h>
.......
副版大
今天因為自修c語言
在後面習題剛好和副版大的猜數字遊戲差不多
因此就以您的原始碼改寫成c語言的格式
因為std::string again;這小弟不懂成員函數的呼叫
所以就刪除了
但是如今卻無法在猜完後還能繼續的玩
如此之故
不知可否請教副版大
這程式碼要怎麼改才可以
謝謝
底下是小弟改寫的方式
大部份都照大大原碼
很不好意思
在此請教了

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
int main( int argc, char *argv [] )

{
  char again;
  int byby = 5;
  srand((unsigned) time(NULL)); //剛更新 ^^  
  int min = 0, max = 99, round = 0, this_round = rand()%100+0;
  int player;    
  while(byby == 5)
  {         printf(" max=%d; min=%d;\n",max,min);    
          printf("I Guess :");
          scanf("%d",&player);
          printf("\n");
           
          if (player <= min || player >= max)
          {
                  printf("注意!!!\n") ;
                 
                  if (player <= min)
                  player = min;
                  else if (player >= max)
                      player = max;
          }
          else
          {
          if (player == this_round)
          {
                  if (round == 0)
                  {
                        printf("真厲害!! 一次就猜中!");
                        printf("另起新局? (Y/N)" );
                        printf("   ------>");
                        again=getche();
                         
                        if(again=='Y'||again=='y')
                        {
                                min = 0;
                                max = 99;
                                round = 0;
                                this_round = rand () % 100 + 0;
                        }
                        else
                                break;
                  }
                  else
                  {              
                                printf( "\n..bingo.. 猜數字遊戲 %d次猜中 \n", round);
                 
                               
                                printf("另起新局? (Y/N)");  
                                printf("   ------>");
                                scanf("%c",&again);
                               
                                if (again == 'Y' || again == 'y')
                                {
                                      min = 0;
                                      max = 99;
                                      round = 0;
                                      this_round = rand () % 100 +0;
                                }
                                else
                                    break;  
                  }
          }
          else
          {
              if (player > this_round)
              {
                    max = player;
                    printf("數目猜小一點\n");
              }
              else
              {
                min = player;
                printf("數目猜大一點\n");
              }
              round += 1;
          }
          }
  }
 
    system("pause");
    return 0;
}

獻花 x0
引用 | 編輯 星辰雪
2011-04-18 23:40
10樓
  
std::string again;

定義 型態為STRING
變數名稱為 again

如同你定義的 char string;
---------------------------------------

修改完之後,有點小bug 不知道 有沒有發現。
結束之後可以選擇是否繼續遊戲,不管選擇Y or N
都會結束程式。

獻花 x0
引用 | 編輯 csr
2011-04-19 15:50
11樓
  
下面是引用 星辰雪 於 2011-04-18 23:40 發表的 : 到引言文
std::string again;

定義 型態為STRING
變數名稱為 again

如同你定義的 char string;
---------------------------------------

修改完之後,有點小bug 不知道 有沒有發現。
結束之後可以選擇是否繼續遊戲,不管選擇Y or N
都會結束程式。

大大
就是因為如此
所以才發出sos求救
不知大大對於這情形可不可以幫忙改一下程式碼
謝謝

已自行解決
謝謝大大

獻花 x0
引用 | 編輯 星辰雪
2011-04-23 21:54
12樓
  
下面是引用 csr 於 2011-04-19 15:50 發表的 : 到引言文


大大
就是因為如此
所以才發出sos求救
不知大大對於這情形可不可以幫忙改一下程式碼
謝謝

- - 不好意思 我也找不出來
錯誤在哪邊

獻花 x0