引用 | 編輯
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 |
引用 | 編輯
wing50kimo
2011-04-09 03:45 |
8樓
▲ ▼ |
對於我這個初學者真的是獲益良多~
謝謝分享~ x0 |
引用 | 編輯
csr
2011-04-18 20:41 |
9樓
▲ ▼ |
下面是引用 sk@.@ 於 2010-11-06 01:54 發表的 第二次試作 修了第1次隨機數為42的bug,|猜數字:副版大 今天因為自修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 |