如題
當我執行這遊戲時 遊戲結束時 我有設定2個選項
分別是 在玩一次 及 結束程式
但當我執行再玩一次 卻有問題


有大大能幫忙看一下怎麼改嗎 謝謝
C++ 21點程式問題



附上程式

#include <iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int random( bool a[] ) {
int card;



do {
card = rand() % 52;
}while( a[card] == true );
a[card] = true;
return card;
}
int card( int x ) {
x %= 13;
if( x < 10 ) {
cout << x + 1 << " ";
return x + 1;
} else if( x == 10 )
cout << "J ";
else if( x == 11 )
cout << "Q ";
else if( x == 12 )
cout << "K ";
return 10;
}
int main() {
int z;
for(z=1;z<3;z++) {

srand(time(NULL));
bool a[52];
int p = 0, cp = 0, t, ct, cc, c;
char *s[] = {"黑桃 ", "梅花 ", "菱形","紅心 "};
char ch;
do {
if( cp < 17 ) {
cc = random( a );
cout << s[ cc % 4 ];
ct = card( cc );
if( cp + ct > 21 ){
cout << "莊家 " << cp + ct << " 點爆了,你贏囉!" << endl;
break;
} else {
if( ct == 1 && cp == 10 )
cp = 21;
else
cp += ct;
cout << "莊家 " << cp << " 點" << endl;
}
} else if( cp >= 17 ) {
cout << "莊家 " << cp << " 點,不補牌" << endl;
}
if( ch != 'n' && ch != 'N' ){
c = random( a );
cout << s[ c % 4 ];
t = card( c );
if( p + t > 21 ){
cout << "你 " << p> break;
} else {
if( t == 1 && p == 10 )
p = 21;
else
p += t;
cout << "你 " << p> if( p < 21 ){
cout << "要補牌嗎?(y/n)";
cin >> ch;
system("cls");
} else
ch = 'n';
}
} else {
cout << "你 " << p> if( cp >= 17 ) {
if( p > cp )
cout << "你贏囉!" << endl;
else if( p < cp )
cout << "你輸呵呵!" << endl;
else
cout << "沒輸沒贏 !" << endl;
break;
}
}
}while( cp <= 21 && p <= 21 );
cout<<"再玩一次請按1"<<endl;
cout<<"退出請按2"<<endl;
cin>>z;
system("cls");
}
return 0;
}
我還是不要說好了。
kevin24i7 wrote:
分別是 在玩一次 及 結束程式
但當我執行再玩一次 卻有問題(恕刪)

在要跳去 再玩一次 那裡 設一個 斷點..

當你選了再玩一次時, 就會被 debugger 攔截下來,

然後, 你就開始 單步執行..

看看 單步到 哪裡, 會出現不是你預期 執行狀況..
kevin24i7 wrote:
如題

當我執...(恕刪)

因為你紀錄要不要補牌的ch變數在你不補牌的時候變為n,然後ch就一直維持在n,所以再玩一次就會直接跳不補牌,整個程式的邏輯你要再重新想一下
文章分享
評分
評分
複製連結

今日熱門文章 網友點擊推薦!