1

プログラムをcards終了すると、ユーザーが終了した後に表示する必要があると言われました。

変数をdraw返してそれを出力し、int に変換したの各結果を保存しようとしました。無効な作業関数を示していますが。handdraw()

これまでのところ何も機能せず、私は迷っています。

void draw(int deck[SIZE], int a) {
    int numCards = 10;
    int i; 
    int hand[numCards];
    int card;
    for(i = 0; i < numCards && top > 0; i++) {
        card = deck[top-1];     
        hand[i] = card; 
        top--;   
    }
    if(a != 0) {
        printcards(card);
    } else {
        for(i = 0; i < numCards && top > 0; i++)
        printcards(card);
    }
}

プログラムは、描画および編集されたバージョンが次のように見えるようにカードを印刷できます。

int draw(int deck[SIZE], int a) {
    int numCards = 10;
    int i; 
    int hand[numCards];
    int card;
    for(i = 0; i < numCards && top > 0; i++) {
        card = deck[top-1];     
        hand[i] = card; 
        top--;   
    }
    if(a != 0) {
        printcards(card);
    } else {
        for(i = 0; i < numCards && top > 0; i++)
        printcards(card);
    }
    return card; /* or return hand */
}
void printcards(int card) {
    char suits[4][9] = {
        "Hearts",
        "Diamonds",
        "Clubs",
        "Spades"
    };
    if(card%13 == 0 || card%13 == 10 || card%13 == 11 || card%13 == 12) {
        printf("%s ", facecheck(card%13) );
    } else {
        printf("%d ", card%13+1);
    }
    printf("of %s \n", suits[card/13]);
}

この関数は、カードの実際の印刷です。

void players(int deck[]) {
    int x;
    int a; 
    int yourhand[10];

    a = 1;

    printf("Player 1 \n"); 
    printf("Your Hand is: \n"); 
    draw(deck, a);
    draw(deck, a);
    while(a == 1) {
        printf("What would you like to do: Press 1 to Draw. 2 to Stay. \n"); 
        scanf("%d" , &x); 
        if(x == 1) {
            draw(deck, a);
        } else { 
            a--;
        }
    }
}

この関数は、draw()ユーザー入力を使用して を呼び出しdisplay()、else の後にを追加するa--か、描画の結果を手に格納して結果を出力する必要があります。これまでのところ、何も機能していません。

4

0 に答える 0