因此,我正在尝试创建一个C代码程序,该程序将为纸牌赋予简写形式,并将确定格式化的纸牌。例
输入:H 8
输出:8心
Input: C 14
Output: Ace of Clubs
等级:2-10,11 Jack,12 Queen,13 King,14 Ace
套装:C球杆,D钻石,H心,S黑桃
但是在实施的最后阶段,我遇到了几个严重的问题。当我像D 5一样输入时,程序运行正常,但输入D 12将使它成为女王,然后是12位钻石。
继承人代码:http://pastebin.com/Tj4m6E2L
这是当前的EXE:http://www.mediafire.com/download/4fy4syga2aj8n2j
感谢您的任何帮助,您可以提供。我是C代码的新手,所以为了我的利益,请使其变得简单而愚蠢。
最佳答案
您在break
中缺少重要的switch
语句,例如
switch(rank)
{
case 14:
{
if(suite == 'H')
printf("Your card is the Ace of Hearts!");
else if(suite == 'C')
printf("Your card is the Ace of Clubs!");
else if(suite == 'D')
printf("Your card is the Ace of Diamonds!");
else
printf("Your card is the Ace of Spades!");
}
// <<< NB: case 14 "falls through" to case 13 here !!!
case 13:
...
更改为:
switch(rank)
{
case 14:
{
if(suite == 'H')
printf("Your card is the Ace of Hearts!");
else if(suite == 'C')
printf("Your card is the Ace of Clubs!");
else if(suite == 'D')
printf("Your card is the Ace of Diamonds!");
else
printf("Your card is the Ace of Spades!");
}
break; // <<< FIX
case 13:
...
对所有其他缺少的
break
语句重复上述步骤。