Programming Homework: Rigging a deck of cards in C -


i have assignment i've been working on. supposed have deck of cards , distribute evenly 4 players.

each card has own value (two = 1, three=2, ..., king=12, ace=13) , suit has own value (clubs = 1, diamonds = 2, hearts = 3, spades = 4)

i'm supposed make dealer (player p) win 75% of time swapping out cards, or along lines. program wrote emulates cards having single array 0 51. program runs, command prompt says "press key continue ..."

can please @ code , tell me if there's might causing this? in advance.

#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> #include <algorithm>  #define deck 52 #define cards 52 #define suits 4 #define faces 13  int deck[deck]; void distributecards(int i); void swap(int i, int j); void shuffle(unsigned int wdeck[][faces]);  int main(void) {      int deck[deck] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };  }  void swap(int i, int j) {     int temp = deck[i];     deck[j] = deck[i];     deck[i] = temp; } int max(int i, int j, int k, int l) {     int tempmax = deck[i];     int maxindex = i;      if (deck[j] > tempmax)     {         tempmax = deck[j];         maxindex = j;     }     if (deck[k] > tempmax)     {         tempmax = deck[k];         maxindex = k;     }     if (deck[l] > tempmax)     {         tempmax = deck[l];         maxindex = l;     }     return maxindex; }  int determineface(int i) {     if (i % 4 == 0)         return 3; // 3 = hearts     if (i % 4 == 1)         return 2; // 2 = diamonds     if (i % 4 == 2)         return 4; // 4 = spades     else         return 1; // 1 = clubs }  int determinevalue(int i) {     if (i / 4 == 0) return 1; // 1 = 2     if (i / 4 == 1) return 2; // 2 = 3     if (i / 4 == 2) return 3; // 3 = 4     if (i / 4 == 3) return 4; // 4 = 5     if (i / 4 == 4) return 5; // 5 = 6     if (i / 4 == 5) return 6; // 6 = 7     if (i / 4 == 6) return 7; // 7 = 8     if (i / 4 == 7) return 8; // 8 = 9      if (i / 4 == 8) return 9; // 9 = ten     if (i / 4 == 9) return 10; // 10 = jack     if (i / 4 == 10) return 11; // 11 = queen     if (i / 4 == 11) return 12; // 12 = king     else return 13; // 13 = ace }  void distributecards() {     int house[13]; // house = player p     int p1[13]; // p1 = player q     int p2[13]; // p2 = player r     int p3[13]; // p3 = player s        //picking house's cards     printf("\n\nplayer p's cards: \n");     (int = 0; < 13; i++)     {         int rand1 = (rand() % (51 - i)) + i;         int rand2 = (rand() % (51 - i)) + i;         int rand3 = (rand() % (51 - i)) + i;         int rand4 = (rand() % (51 - i)) + i;         int rand = max(rand1, rand2, rand3, rand4);         house[i] = deck[rand];         swap(rand, i);     }       //picking p1's cards     printf("\n\nplayer q's cards: \n");     (int = 13; < 26; i++)     {         int rand5 = (rand() % (51 - i)) + i;         p1[i - 13] = deck[rand()];         swap(rand(), i);     }     //picking p2's cards     printf("\n\nplayer r's cards: \n");     (int = 26; < 39; i++)     {         int rand6 = (rand() % (51 - i)) + i;         p2[i - 13] = deck[rand()];         swap(rand(), i);     }     //picking p3's cards     printf("\n\nplayer s's cards: \n");     (int = 39; < 51; i++)     {         int rand7 = (rand() % (51 - i)) + i;         p3[i - 13] = deck[rand()];         swap(rand(), i);     } } 

the behavior fine. have written main function:

int main(void) {         int deck[deck] = {....}; } 

which nothing except defining array. no input, no output, nothing. "press key continue" means array defined correctly , destroyed correctly , program run correctly , terminated.

edit:

i think need like:

int main(void) {   int deck_temp[deck] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,                      17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,                      31, 32, 33, 34, 35,  36, 37, 38, 39, 40, 41, 42,                      43, 44, 45, 46, 47, 48, 49, 50, 51 };     memcpy(deck, deck_temp, 52*sizeof(int));    distributecards(); } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -