go fish!

Put the code you need help with here.
This is my code so far for a go fish game. I'm having trouble looping through each card to check if it's the value the player and computer are looking for. Also, I need help adding points to the player or computer scores.

Thanks!


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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
void humanTurn(Deck, int[], int[], int, int, int)
{

}

void computerTurn(Deck, int[], int[], int, int, int)
{

}


int main()
{
	vector<Card> hand;
	Deck deck;
	deck.shuffle();
	//vector<Card>hand = deck.dealCards(5);
	hand = deck.dealCards(5);

	{
		char yesOrNo = 'y';
		while (yesOrNo == 'y' || yesOrNo == 'Y')
		{
			int humanHand[5];
			int humanHandSize = 0;
			int computerHand[5];
			int computerHandSize = 0;
			int drawn = 0;
			int humanScore = 0;
			int computerScore = 0;
			int i;

			for (i = 0; i < 5; i++)
			{
				(deck, humanHand, humanHandSize, drawn);
			}

			for (i = 0; i < 5; i++)
			{
				(deck, computerHand, computerHandSize, drawn);
			}

			for (i = 0; i < humanHandSize; i++)
			{
				cout << humanHand[i] << " ";
			}

			for (i = 0; i < computerHandSize; i++)
			{
				cout << computerHand[i] << " ";
			}

			bool breaking = false;
			while (drawn != 3 && humanHandSize != 0 && computerHandSize != 0 && !breaking)
			{

				humanTurn(deck, humanHand, computerHand, humanHandSize, computerHandSize, humanScore);
				if (computerHandSize == 0)
				{
					breaking = true;
					cout << "Game Over." << endl;
				}
				else
				{
					computerTurn(deck, computerHand, humanHand, computerHandSize, humanHandSize, computerScore);
				}
				if (humanHandSize == 0)
				{
					breaking = true;
					cout << "Game Over." << endl;
				}


			}
			cout << " *Final Score*" << endl;
			cout << " Your Score: " << humanScore << endl;
			cout << " Computer Score: " << computerScore << endl;
			cout << " Would you like to play again? (y/n) ";
			cin >> yesOrNo;
		}
	}
	return 0;
}

void stealCards(int rank, int from[], int& fromSize, int to[], int& toSize)
{
	int i;
	for (i = fromSize - 1; i >= 0; i--)
	{
		if (from[i] == rank)
		{
			to[toSize] = rank;
			toSize++;
			fromSize--;
			from[i] = from[fromSize];
		}
	}
}
void humanTurn(int deck[], int humanHand[], int computerHand[], int& position, int& humanHandSize, int& computerHandSize, int& score)
{
	int count = 1;
	char noun[] = "You";
	bool breaking = false;
	while (count > 0 && !breaking)
	{
		int i;
		cout << "You have: ";
		for (i = 0; i < humanHandSize; i++)
		{
			cout << humanHand[i] << " ";
		}
		cout << endl;

		int guess;
		cout << "You ask if I have any ";
		cin >> guess;
		cout << endl;

		count = (guess, computerHand, computerHandSize);
		stealCards(guess, computerHand, computerHandSize, humanHand, humanHandSize);

		if (count > 0)
		{
			cout << "Yes I do. I have " << count << endl; // How do you check hand for card? Loop through each?
		}

	}

}
Last edited on
PLEASE learn to use code tags.

http://www.cplusplus.com/articles/jEywvCM9/

And include the header files so your code snippet is compileable without having to add them.
I have my header files which were given by my professor so I know they work, just need to fix main cpp file
Topic archived. No new replies allowed.