How do you remove duplicate values from an array

Hello, I am writing a Go Fish! game in C++. I am currently working on my "checkSet" function. It identifies a set of cards and removes them from the player's hand. Also, it adds a score to the player, and the game continues until the player or computer reaches a score of 4.

For example, if you have 2, 4, 4, 6, 4, 7, 4, "checkSet" will remove all 4's from the hand and add 1 score point. Your hand will be now 2, 6, 7.

How can I implement this in C++?

Note: This program only uses 2's through 9's (only 32 cards are used).

This program is incomplete. We will call this function in the main, and computersTurn & playersTurn(which I did not write yet).

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
86
87
88
89
90
91
92
93
94
95
#include <iostream>
using namespace std;

void shuffleCards (int[], int& position);
void drawCards (int ocean[], int& oceanPos, int hand[], int& handSize, int &drawn );
void stealCards(int, int& [], int&, int& [], int&);

int main()

{
char yesNo = 'y';
while (yesNo == 'y') {
    int ocean [32];
    for (int i = 0; i < 32; i++)     // initialize the deck
    {
        ocean [i] = 2 + rand() % 9;
    }
    // Declare variables
    int oceanPos;
    int playerHand [32];
    int computerHand[32];
    int playerSize = 0;
    int computerSize = 0;
    int drawn;

    shuffleCards (ocean, oceanPos);     //shuffles the card

    for (int i = 0; i < 5; i++)
    {
        drawCards(ocean, oceanPos, playerHand, playerSize, drawn);
    }
    for (int i = 0; i < 5; i++)
    {
        drawCards(ocean, oceanPos, computerHand, computerSize, drawn);
    }

    cout << "Would you like to play again?";
    cin >> yesNo;
}
return 0;
}

void shuffleCards (int ocean[], int& position)
{
int i;
int j;
int temp; // temporary storage
for (i = 0; i < 32; i++) {
    j = 1 + rand() % 32;
    temp = ocean[i]; // store in temp
    ocean [i] = ocean[j]; // j fills the empty i
    ocean [j] = temp; // temp(or i) goes to empty j.
}
position = 0;
}


void drawCards ( int ocean[], int& oceanPos, int hand[], int& handSize, int &drawn )
{
drawn = ocean[oceanPos]; 
handSize++;   // increase the player's cards count
hand[handSize] = drawn; // make a room for the new card
oceanPos++; 
}

int countRank ( int rank, int hand[], int handSize ) 
{
int i;
int count = 0;
for ( i = 0; i < handSize; i++ )
{
    if ( hand[i] == rank )
    {
        count++;
    }
}

return count;
}

 void stealCards (int rank, int& from[], int& fromSize, int& to[], int& toSize )
 {
           for (int i = 0; i < fromSize; i++ )
           {
        if (from[i] == rank)
       {

        toSize++;
        to[toSize] = rank;
        fromSize--;
        // how do you remove an value from From? Thanks. 

      }
  }
  }
The basic function could be something like this:
1
2
3
4
5
6
7
 
//Pseudocode 
-Iterate through the playerhand array looking for any 2s. 
-If a 2 is found, ++count, store location in location[count]. 
-If count == 4 
-Remove cards from the 4 locations 
-Do the same for the other numbers (making sure to reset count to zero). 
Topic archived. No new replies allowed.