. findWinner( total[. findWinner( total[. ( total[DEALER] == . printf(. . ( (total[DEALER] > ) && (total[PLAYER] > . printf(, . . ((total[DEALER] >= total[PLAYER])&& (total[DEALER] < . printf(. . ((total[PLAYER] > )&& (total[DEALER] < . printf(. . printf(,. . }
void findWinner(int total[]);
void findWinner(int total[])
{
if ( total[DEALER] == 21 )
{
printf("The house wins.\n");
return ;
}
if ( total[DEALER] > 21 )
{
if( total[PLAYER] > 21 )
{
printf("%s", "Nobody wins.\n");
return ;
}
}
if ( total[DEALER] < 21 )
{
if( (total[PLAYER] > 21) )
{
printf("The house wins.\n");
return ;
}
if( (total[DEALER] >= total[PLAYER]) )
{
printf("The house wins.\n");
return ;
}
}
printf("%s%c","You win!\n",BELL);
return;
}
/* 21點游戲:對《寫給大家看的C語言書》附錄B之21點程序的重構 */
#include <stdio.h>
typedef
enum
{
NO ,
YES,
}
YESNO ;
YESNO again( void );
void game_21( void );
int main( void )
{
do{
game_21(); //一輪游戲
}while ( again() == YES );
return 0;
}
void game_21( void )
{
//待完成
}
YESNO again( void )
{
int c;
puts("繼續游戲(Y/N)?");
c = getchar() ;
while ( getchar() != '\n'){ //讀完一行
}
if ( c=='y' || c == 'Y' ){
return YES;
}
return NO;
}