BlackJack

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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include <iostream>
using namespace std;

  
int main ()
{ 

	char cards, repeat = 'N';
	int number_of_cards;
	int total_card_value = 0;
	int card_value = 0;
	int card_value1 = 0;
	int card_hand = 0;
	int aces = 0;
	int counter = 0;
	
	
// Ask the user how many cards she or he has:
	cout << "Welcome to the program blackjack!" << endl;
	cout << "The program consists of the following: a player receives from two to five cards" << endl;
	cout << "The face cards- jack, queen, and king are scored as 10 points. The goal is" << endl;
	cout << "to come as close to a score of 21 as possible without going over 21." << endl;
	cout << "How many cards do you have? \n " ;
	cin >> number_of_cards;
	cout << endl;


// Input characters representing the cards that is, 2, 3, 4, or 5.
// Using a for loop:

	{
	for (card_hand = 2 ; card_hand <= 5; card_hand++)
	cout << " What are the card values? " << endl;
	cin >> cards;
	counter ++;



switch (cards)
{ 

case '2':
	card_value = card_value + 2;
	card_value1 = card_value + 2;
	break;

case '3':
	card_value = card_value + 3;
	card_value1 = card_value + 3;
	break;

case '4':
	card_value = card_value + 4;
	card_value1 = card_value + 4;
	break;

case '5':

	card_value = card_value + 5;
	card_value1 = card_value + 5;
	break;

case '6':
	card_value = card_value + 6;
	card_value1 = card_value + 6;
	break;

case '7':
	card_value = card_value + 7;
	card_value1 = card_value + 7;
	break;

case '8':
	card_value = card_value + 8;
	card_value1 = card_value + 8;
	break;


case '9':
	card_value = card_value + 9;
	card_value1 = card_value + 9;
	break;


case 'T':
	card_value = card_value + 10;
	card_value1 = card_value + 10;
	break;

case 'J':
	card_value = card_value + 10;
	card_value1 = card_value + 10;
	break;

case 'Q':
	card_value = card_value + 10;
	card_value1 = card_value + 10;
	break;

case 'K':
	card_value = card_value + 10;
	card_value1 = card_value + 10;
	break;

case 'A':
	card_value = card_value + 10;
	card_value1 = card_value + 10;
	break;

case 't':
	card_value = card_value + 10;
	card_value1 = card_value + 10;
	break;

case 'j':
	card_value = card_value + 10;
	card_value1 = card_value + 10;
	break;

case 'q':
	card_value = card_value + 10;
	card_value1 = card_value + 10;
	break;

case 'k':
	card_value = card_value + 10;
	card_value1 = card_value + 10;
	break;

case 'a':
	card_value = card_value + 10;
	card_value1 = card_value + 10;
	break;       
	

// Use a while loop to take care of aces.


 }
	
	 { while (aces > 0) 

		{
		if (total_card_value <= 10)

			total_card_value = total_card_value + 11;

		else if (total_card_value > 10)

			total_card_value = total_card_value + 1;
			aces --;

		}

 

	if  (total_card_value < 21)

		{

		cout << " Your total score is: " << total_card_value << endl;

		}

		else if (total_card_value = 21)

			{

			cout << " Very well.";

			cout << "Your total score is: " << total_card_value << endl;

			}

		else if (total_card_value > 21)

			{
	   cout << "BUSTED! \n";

			cout << "Your score: " << total_card_value << endl;

			}

	cout << " Do you want to repeat? Yes or No? \n"; 
	cin >> repeat;  

// While loop to let the user repeat the calculation:

	} while ((repeat == 'Y') || (repeat == 'y')); 
}
cout << endl;
return 0;
}
Uhm?
Oh sorry, I just needed to show someone my code. I sent them the link.
http://ideone.com/

Shows the workings code! (:
I have never heard of that site before, thank you so much!
No problem. (:
Also, if you and a friend want to code at the same time, on the same project:
http://collabedit.com/
You are so nice, thank you very much!
Again, no problem! lol (:
I may seem like a stalker but your webpage https://sites.google.com/site/davevisone/ is wonderful! I hope someday to be as good as you!
ahaha thanks! You should aspire to be better! Never settle for "As good..." lol!

Cause I could be better, and I should be! (:
You're welcome! Such great advice! I wish you all the luck and once again, thank you! :))
lol, thanks. You too! (:
Topic archived. No new replies allowed.