所以我创建了一个(主要是工作的)扑克手牌计分表,我目前唯一遇到的问题是我需要对卡片的值进行排序,以便正确识别顺子或类似牌。
目前,我的程序返回要显示已排序整数数量的外键。
我当前的输入:6D 7D 9D 8C 5D
我当前的输出:
Six of diamonds
Seven of diamonds
Nine of diamonds
Eight of clubs
Five of diamonds
� <--- (This is where I have told it to display the Numbers in order)
High Card! 1 point.
基本上我知道我的得分是正确的,只是排序不起作用。
我的代码
#include <stdio.h>
int main( void )
{
char cardval[10] = {'\0'}, count;
char maincard[2] = {'\0'};
int intval[5], i;
int tempval;
int dupecount = 0;
int suitcount = 0;
int a;
for(count=0;count<10;count++)
{
scanf(" %c", &(cardval[count] ) );
scanf(" %d", &(intval[i]) );
i++;
count++;
scanf(" %c", &(cardval[count] ) );
strcpy( maincard, &cardval[count-1] );
strcat( maincard, &cardval[count] );
switch (maincard[0])
{
case '2':
printf ( "Two of ");
break;
case '3':
printf ( "Three of ");
break;
case '4':
printf ( "Four of ");
break;
case '5':
printf ( "Five of ");
break;
case '6':
printf ( "Six of ");
break;
case '7':
printf ( "Seven of ");
break;
case '8':
printf ( "Eight of ");
break;
case '9':
printf ( "Nine of ");;
break;
case 'J':
printf( "Jack of ");
break;
case 'Q':
printf( "Queen of ");
break;
case 'K':
printf( "King of ");;
break;
case '0':
printf( "Ten of ");
break;
case 'A':
printf( "Ace of ");
break;
default:
printf( "\n %c is an incorrect input, please enter a number 0, 2-9, A,K,Q,J", maincard[0]);
return 0;
break;
}
switch (maincard[1])
{
case 'D':
printf( "diamonds");
break;
case 'S':
printf( "spades");
break;
case 'H':
printf( "hearts");
break;
case 'C':
printf( "clubs");
break;
default:
printf( "\n %c is an incorrect input, please enter D, S, H, or C as a suit", maincard[1]);
return 0;
break;
}
printf ("\n");
}
for ( a=0; a<5; a++ )
{
for ( i=0; i<5-1; i++)
{
if ( intval[i] > intval[i+1])
{
tempval = intval[i];
intval[i] = intval[i+1];
intval[i+1] = tempval;
tempval = intval [i];
}
}
}
printf("%c", intval);
我的代码排序部分有什么问题?似乎没有正确记录 intval。