我需要为学校作业创建一个纸牌游戏,我试图在输出中显示心脏,钻石,黑桃和俱乐部符号。
老师告诉我们使用char(3),char(4)等,但输出显示一个问号。我在Windows 10上使用Visual Studio 2017。
我不太熟悉Unicode或ASCII的东西,如果有人可以帮助我,我还有3天的时间来提交这个作业!!我是初学者
谢谢
//对于COMP 218部分EC(2017年冬季) - Concordia大学
cout << char(3) << char(4) << char(5) << char(6) << char(3) << char(4) << char(5) << char(6) << char(3) << char(4) << char(5) << char(6) << endl
<< "\t \t Welcome to Shawn's Card Dealing Program" << endl
<< char(3) << char(4) << char(5) << char(6) << char(3) << char(4) << char(5) << char(6) << char(3) << char(4) << char(5) << char(6);
cout << "RULES: \nTwo cards are dealt at a time. They are then compared. \nSince there are two decks of cards, you may have identital cards. \nI will tell you if they are the same or not" << endl
<< "or if they just have the same suit or rank. \nOnce I finish comparing the two cards, they are returned to the deck, the deck is reshuffled and two more cards are dealt. \n \n" << endl
<< "So how many pairs shall I deal? (1 to 15 max): \n > ";
while (!valid)
{
valid = true;
cin >> loops;
if (cin.fail() || loops < 1 || loops > 15)
{
cin.clear();
cin.ignore();
cout << "Please enter an integer between 1 and 15:" << endl << "> ";
valid = false;
}
}
int pairCount = loops;
do
{
card1.genRandom();
card2.genRandom();
cout << "Pair " << setw(2) << pairCount - loops + 1 << " - ";
card1.printCard();
card2.printCard();
cout << endl;
if (card1.sameCard(card2) == true)
{
cout << "same card" << endl;
ident += 1;
}
else
{
if (card1.sameSuit(card2) == true)
{
cout << "same suit" << endl;
sameSuit +=1;
}
if (card1.sameRank(card2) == true)
{
cout << "same rank" << endl;
sameRank += 1;
}
if (card1.sameRank(card2) == false && card1.sameSuit(card2) == false)
{
cout << "both different" << endl;
different +=1;
}
}
loops -= 1;
} while (loops > 0);
cout << "Identical: " << ident << endl;
cout << "Same Suit: " << sameSuit << endl;
cout << "Same Rank: " << sameRank << endl;
cout << "Both different: " << different << endl;
}
答案 0 :(得分:0)
您可能没有使用ASCII,并且实际上已被指示使用不同的编码,因为对于不在ASCII字符集中的游戏卡套装字符的要求就证明了这一点。 (几乎没有提及ASCII而没有引用规范是非常可疑的。)
您可能正在使用CP437(在命令提示符中转到chcp
。)CP437是其中3,4,5,6是扑克牌套装的编码之一。使用命令提示符编码可以方便地设置您的系统,这对于法语来说更有用。如果是这样,您每次打开此程序的命令提示符时都可以运行chcp 437
。
为此,您的命令提示符还必须设置支持字符的字体。我认为绝大多数字体都支持扑克牌套装字符,所以这可能不是问题。