[SOLVED]Question about an exersize I'm doing.

Alright so this one I think I just been programming to much today and I'm missing something completely stupid. What I have to do is create a 2d Array that is a deck of cards which is the size of a normal pack of cards etc "int deck[4][13];" Now we have to see every element in the array to the value of "1". Once that's done I have to step through the array and take out every 5th element until the pack of cards has no cards in it. I know this is basic but trying to get rid of the 5th element is getting annoying as I think I've got my logic for it totally wrong.

Anyway here's what I've made so far:
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdio.h>
#include "HelperFunctions.h"
#define FIVE 5

void main()
{
	int deck[4][13];

	for(int row = 0; row < 4; ++row)
	{
		for(int col = 0; col < 13; ++col)
		{
			deck[row][col] = 1;
		}
	}

	int totalCards = 0;
	int cardDeleter = 0;

	int i = 0;

	do
	{
		totalCards = 0;
		printf("\n**********Deck Of Cards**********\n");
		printf("\tA 2 3 4 5 6 7 8 9 1 J Q K\n");
		printf("                          0\n");
		for(int row = 0; row < 4; ++row)
		{
			if(row == 0){printf("Clubs\t");}
			if(row == 1){printf("Diamonds");}
			if(row == 2){printf("Spades\t");}
			if(row == 3){printf("Hearts\t");}
			for(int col = 0; col < 13; ++col)
			{
				printf("%d ", deck[row][col]);

				if(deck[row][col] == 1)
				{
					totalCards++;
				}
			}
			printf("\n");
		}
		printf("*********************************\n");
		printf("\nTotal Cards Remaining : %d", totalCards);

		
		cardDeleter = cardDeleter + FIVE;
		if(cardDeleter < 13)
		{
			if( i == 0 )
			{
				deck[0][cardDeleter] = 0;
			}
			if( i == 1 )
			{
				deck[1][cardDeleter] = 0;
			}
			if( i == 2 )
			{
				deck[2][cardDeleter] = 0;
			}
			if( i == 3 )
			{
				deck[3][cardDeleter] = 0;
			}
		}
		if(cardDeleter > 13)
		{
			cardDeleter -= 13;
			if( i < 4 )
			{
				i++;
			}
			else
			{
				i = 0;
			}
		}

		Wait(1, 100);
		ResetCursorPosition(0,0);
	} while(totalCards != 0);
}


So basically I need to figure out what I'm doing wrong with lines 49 to 80.

Thanks
Last edited on
Figured it out:

If anyone knows a better way though feel free to list it :)

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdio.h>
#include "HelperFunctions.h"
#define FIVE 5

void main()
{
	int deck[4][13];

	for(int row = 0; row < 4; ++row)
	{
		for(int col = 0; col < 13; ++col)
		{
			deck[row][col] = 1;
		}
	}

	int totalCards = 0;
	int cardDeleter = 0;

	int i = 0;

	do
	{
		totalCards = 0;
		printf("**********Deck Of Cards*********\n");
		printf("*    A 2 3 4 5 6 7 8 9 T J Q K *\n*\t\t\t       *\n");
		for(int row = 0; row < 4; ++row)
		{
			if(row == 0){printf("*%c   ", char(3));}
			if(row == 1){printf("*%c   ", char(4));}
			if(row == 2){printf("*%c   ", char(5));}
			if(row == 3){printf("*%c   ", char(6));}
			for(int col = 0; col < 13; ++col)
			{
				printf("%d ", deck[row][col]);

				if(deck[row][col] == 1)
				{
					totalCards++;
				}
			}
			printf("*\n");
		}
		printf("********************************\n");
	
		if(cardDeleter < 13)
		{
			if( i == 0 ){deck[i][cardDeleter] = 0;}
			if( i == 1 ){deck[i][cardDeleter] = 0;}
			if( i == 2 ){deck[i][cardDeleter] = 0;}
			if( i == 3 ){deck[i][cardDeleter] = 0;}
			int tempCard = cardDeleter;

			if     (tempCard ==  0){printf("Deleted Card %c of %c \n", (char)65, (char)i + 3);}
			else if(tempCard ==  9){printf("Deleted Card %c of %c \n", (char)84, (char)i + 3);}
			else if(tempCard == 10){printf("Deleted Card %c of %c \n", (char)74, (char)i + 3);}
			else if(tempCard == 11){printf("Deleted Card %c of %c \n", (char)81, (char)i + 3);}
			else if(tempCard == 12){printf("Deleted Card %c of %c \n", (char)75, (char)i + 3);}	
			else                   {printf("Deleted Card %d of %c \n", tempCard, (char)i + 3);}
		
		}		
				
		if(cardDeleter >= 13)
		{
			cardDeleter -= 13;
			i++;
		}
		else
		{
			cardDeleter += FIVE;
		}

		if(i == 4){i = 0;}

		Wait(1, 50);
		if(totalCards != 0)
		{
			ResetCursorPosition(0, 0);
		}
	} while(totalCards != 0);
}
Why are you using a two dimensional array for this? Why not just a single dimension? That would simplify things a bit.
Requirements - they are basic tasks in a class atm. Just a few things I'm touching up on as well. In my case I would do it a lot differently but I have to follow by how they want it done.
yes

its just only a Onedimensional array...

how come you are using two-D array

if you just define

#define deck 4 and 13;

maybe you will come up with a good output..
Topic archived. No new replies allowed.