Tag: 说明符

用scanf()读取字符

此代码适用于掷骰子游戏 。 #include #include #include #include int roll_dice(void); bool play_game(void); int main() { int i, ch,win = 0,lose = 0; bool flag; srand((unsigned)time(NULL)); do { flag = play_game(); if(flag) { printf(“You win!”); win++; } else { printf(“You lose!”); lose++; } printf(“\n\nPlay again(Y/N)? “); scanf(“%c”, &ch); ch = getchar(); printf(“\n”); }while(ch == ‘Y’ || ch == […]