簡體   English   中英

毛牌游戲C++

[英]MAO card game in C++

所以我想編寫一個名為 Mao 的紙牌游戲。 在這個游戲中,玩家將獲得第一張帶有字母 A、B、C 或 D 以及從 1 到 9 的數字的卡片。他們必須放置他們擁有的另一張卡片,但它們必須是相同的字母或相同的數字。 例如,如果第一張牌是 A7,則玩家只能是 A8、D7 等等。 但是他們不能放C3。 在我的程序中,用戶輸入第一張名為“第一”的卡片,然后輸入其他名為“第二”的卡片。 如果用戶可以按照游戲規則使用其中一張牌,程序應返回“是”。如果不能,則返回“否”。 我的代碼是:

using namespace std;

int main()
{
string first = "";
string second = "";
cout<<"enter first card: "<<endl;
cin>>first;
for (int i = 0 ;i < 5 ;i++)
{
    cin>>second;
    
    
}
for (int i = 0; i < 5 ;i++)
{
    if (second[0]==first[0] || second[1]==first[1])
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"no"<<endl;
    }
}
return 0;

}

output 應該是這樣的:

enter first card:
A7
A9
C1
B7
D7
D5
Yes
no
Yes
Yes
no

但它只顯示“是”。 有誰知道如何解決這一問題?

#include <iostream>

using namespace std;

int main()
{
string first="";
string second[5];
cout<<"Enter first card: "<<endl;
cin>>first;
for (int i=0; i<5;i++)
{
    cin>>second[i];
}
cout<<"------------------------"<<endl;
for (int i=0; i<5; i++)
{
    if (second[i][0]==first[0] || second[i][1]==first[1])
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}

return 0;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM