search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

[C/C++基礎]-猜數字遊戲 – jashliao部落格

[C/C++基礎]-猜數字遊戲

本篇要分享猜數字遊戲程式碼,有興趣的(C/P)同好,歡迎來(C/P)一下 ^ ^

程式碼

#include 
#include 
#include 
usingnamespace std;
 
int main()
{
int a,bit=0;
int b[99];
 cin>>a;
while(a>1){
  b[bit]=a%2;
  bit++;
  a=(int)a/2;
 }
    b[bit]=a;
for(int i=bit;i>=0;i--)cout<
 cout<猜數字"<
    srand(time(NULL));
int c[4],d[4],e,ga,gb;
for(i=0;i<4;i++)c[i]=rand();
    do{
     cin>>e;
        d[0]=(int)(e/1000);
  e-=d[0]*1000;
  d[1]=(int)(e/100);
  e-=d[1]*100;
  d[2]=(int)(e/10);
  e-=d[2]*10;
  d[3]=e;
  ga=0;gb=0;
  for(i=0;i<4;i++){
   for(int j=0;j<4;j++){
    if(d[i]==c[j]){
     if(i==j)ga++;else gb++;
    }
   }
  }
  cout<
 }while(d[0]!=c[0]||d[1]!=c[1]||d[2]!=c[2]||d[3]!=c[3]);
 cout<
 system("pause");
return 0;
}

 

 



熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦