鐵之狂傲

 取回密碼
 註冊
搜尋

切換到指定樓層
1#
10鐵幣
[顯示][隱藏]

我們老師要我們用DEV C++做一個do-while的猜拳程式,雙方玩家出拳,某方三勝兩敗時結束對戰,必須紀錄勝敗差,平手不算。

可是我一直搞不懂do-while怎麼做出這個程式,想了老半天都想不出來,希望有大大可以教導我。

要不然下星期絕對交不了作業了,搞不懂的話以後很難繼續學下去了。

最佳解答

西札爾 檢視完整內容

include #include #include using namespace std; int main(void) { int com[3],j,d,g,a,s;//a是輸電腦,s是贏電腦 com[0] = 0; com[1] = 1; com[2] = 2; a = 0; s = 0; srand(time(0)); for(j=0;j
 

私は1人の平凡な人で、どうぞご指導下さい。



平凡な世界もとても楽しくなることができます。

轉播0 分享0 收藏0

回覆 使用道具 檢舉

原文由 風痕戀 於 08-11-29 13:02 發表
do while 可以用來控制遊戲要不要繼續執行..

我有稍微做了一下..

大概就像是這樣



剪刀,石頭,布  

include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int main(void)
{
int com[3],j,d,g,a,s;//a是輸電腦,s是贏電腦
com[0] = 0;
com[1] = 1;
com[2] = 2;
a = 0;
s = 0;
srand(time(0));
for(j=0;j<3;j++)
{
do
{
d=rand()%3;
cout<<"規則====>剪刀:0 石頭:1 布:2 跳出:4"<<endl;
cout<<"*****請出拳:*****"<<endl;
cin>>g;
if (g==0 && com[d]==0)
{
cout<<"剪刀 V.S 剪刀"<<endl;
cout<<"平手!!!\n"<<endl;
}
else if (g==1 && com[d]==1)
{
cout<<"石頭 V.S 石頭"<<endl;
cout<<"平手!!!\n"<<endl;
}
else if (g==2 && com[d]==2)
{
cout<<"布 V.S 布"<<endl;
cout<<"平手!!!\n"<<endl;
}
else if (g==0 && com[d]==1)
{
cout<<"剪刀 V.S 石頭"<<endl;
cout<<"你輸了!!!\n"<<endl;
a++;
}
else if (g==0 && com[d]==2)
{
cout<<"剪刀 V.S 布"<<endl;
cout<<"你贏了!!!\n"<<endl;
s++;
}
else if (g==1 && com[d]==0)
{
cout<<"石頭 V.S 剪刀"<<endl;
cout<<"你贏了!!!\n"<<endl;
s++;
}
else if (g==1 && com[d]==2)
{
cout<<"石頭 V.S 布"<<endl;
cout<<"你輸了!!!\n"<<endl;
a++;
}
else if (g==2 && com[d]==0)
{
cout<<"布 V.S 剪刀"<<endl;
cout<<"你輸了!!!\n"<<endl;
a++;
}
else if (g==2 && com[d]==1)
{
cout<<"布 V.S 石頭"<<endl;
cout<<"你贏了!!!\n"<<endl;
s++;
}
else if (g==4)
{
cout<<"遊戲結束~\n中途而廢是不好的事喔~"<<endl;
system("pause");
return 0;
}
else
{
cout<<"你亂出......請遵守遊戲規則!!!\n"<<endl;
return main();
}
}
while(j>3);}
if(a==3)
{
       cout<<"你連輸三場,會不會太悲慘了!?"<<endl;
       }
       else if(a==2 && s==1)
       {
            cout<<"你輸了兩場(贏了一場),請再接再厲!!"<<endl;
            }
            else if(a==1 && s==2)
       {
            cout<<"你輸了一場(贏了二場),真厲害~~"<<endl;
            }
            else if(s==3)
       {
            cout<<"你連贏三場,你的運氣真好。"<<endl;
            }
            else
            {
                 return main();
                 }
system("pause");
return 0;
}


目前我的能力只能幫你幫到這裡,

後面還是會有平手辦別的問題,也就是平手之後會重計成績。

P.S:猜拳程式碼參考yahoo知識+,成績判別方法個人製作。


[ 本文章最後由 西札爾 於 08-12-1 23:52 編輯 ]
 
- 切望のフリージア -
- 個人詩集 -

回覆 使用道具 檢舉

do while 可以用來控制遊戲要不要繼續執行..

我有稍微做了一下..

大概就像是這樣

do{

   利用亂數來決定電腦出的是剪刀,石頭或者布
   接收使用者輸入的字
   用 if  else if 判斷式來判斷 哪些情況是贏 哪些情況是輸並做累加的動作
   
}while( 在這裡判斷遊戲次數是否等於3 );


剪刀,石頭,布 <~我是把他用成 0 1 2  這樣表示

你可以參考看看
 

回覆 使用道具 檢舉

我認為教導人家程式
並不是把原CODE直接貼上來
 

回覆 使用道具 檢舉

原文由 yaya741228 於 08-12-3 15:38 發表
我認為教導人家程式
並不是把原CODE直接貼上來


你是否有試想過理解較差的人的感受呢??

不是每個人都是天才,

光憑空說明就會懂的。
 

回覆 使用道具 檢舉

謝謝大大的教導,很感謝各位大大,放心吧!我不是那種要程式的人卻不理解的人。
 

回覆 使用道具 檢舉

你需要登入後才可以回覆 登入 | 註冊

存檔|手機版|聯絡我們|新聞提供|鐵之狂傲

GMT+8, 24-5-10 13:27 , Processed in 0.021376 second(s), 15 queries , Gzip On.

回頂部