Game Question

Hello I'm doing an assignment for my c++ class and i need some help with a game I'm making. Its a variation of the card game 21. Below is my code.

The problem i am having is that i have the cards set up to give me them but i dont know where to put the code to output it. If someone could look this over and give me a hand. it would be greatly appreciated

Also The game keeps repeating itself whenever i get asked to be hit or stand i want it to do so but after it shows a new card if the user chooses to give a card

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
130
131
132
133
134
135
136
137
138
139
140
141
#include <iostream>
#include <time.h>
#include <cstdlib>
#include <ctime>


using namespace std;

	void dealCards(int[], int);
	void playCards(int[], int);
	void youWin();
	void youLose();
	void dealerPlay();
	

int main()
{
	srand(time(NULL));
	
	int card[8];
		
	char response = 'Y';
		
	do
	{
	
	int card1, card2, card3, card4, card5, card6, card7, cardTotal;
	char hitStick;
	
	
	srand(time(NULL));
	
	cout << "BLACKJACK" << endl;
	cout << "**********" << endl;
	cout << endl;
	
	cout << "WELCOME TO BLACK JACK" << endl;
	cout << endl;
	cout << "IN ORDER TO WIN THIS GAME YOU WILL HAVE TO GET AS MANY CARDS WITHOUT GOING OVER 21" << endl;
	cout << endl;
	cout << "PRESS [ENTER] TO GET YOUR CARDS" << endl;
	cin.get();
	////////////////////////////////////////////////////////////////////////////////
	dealCards(card, 7); // First function called for random cards.
	playCards(card, 7);
	

	/////////////////////////////////////////////////////////////////////////////////
	system("cls");
	cout << "BLACKJACK" << endl;
	cout << "---------" << endl;
	cout << endl;
	
	cin.get();
		
	}while (response == 'Y' || response == 'y');
	
	return 0;
}
void dealCards(int card[], int size) // function made to deal the cards at random.
{
	int cardTotal;
	
	for(int i=0;i<size;i++) {
		card[i] = rand() % 11 + 1;
	}
	
	cout << "Card 1: " << card[0] << endl;
	cout << "Card 2: " << card[1] << endl;
	
	cardTotal = card[0] + card[1];
	cout << "Total: " << cardTotal << endl;
	
	return;
}

void playCards(int card[], int size) {
	
	int cardTotal = card[0];
	char hitStick;
	
	if(cardTotal == 21)
	{
	cout << "BLACKJACK" << endl;
	cout << "Total is: "<< cardTotal;
	}
	

	for (int i = 1; i < size; i++){	
	    cardTotal += card[i];
	
		if(cardTotal == 21)
			youWin();
		else if (cardTotal < 21)
		
			if(i>=1) {
			cout << "Do you want to hit [h] or stand [s]" << endl;
	        cin >> hitStick;
	        
	        if (hitStick == 'h'){
			 continue;
		}
			if (hitStick == 's'){
				return;
		}
		
		}
			
		else if (cardTotal > 21)
			youLose;
		
	
			
	}
}
void youLose()  //If you bust the hand.
{
	system("cls");
	cout << "BLACKJACK" << endl;
	cout << "---------" << endl;
	cout << endl;
	
	cout << "The deal has been busted" << endl;
	
	return;
}
void youWin() // If you win the hand
{
	system("cls");
	cout << "BLACKJACK" << endl;
	cout << "---------" << endl;
	cout << endl;
	
	cout << "Congratulation, You have won the hand" << endl;
	
	return;
}
void dealerPlay()
{
	return;
}
Last edited on
Topic archived. No new replies allowed.