-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblackjack.cpp
More file actions
58 lines (45 loc) · 1.22 KB
/
blackjack.cpp
File metadata and controls
58 lines (45 loc) · 1.22 KB
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
// Assignment 2 Amelie Cameron
// This program is a simplified version of blackjack for 1 player
// The player is dealt two cards and the can continue to draw until they get close to 21 or bust
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <string>
using namespace std;
int main()
{
int card_1, card_2, new_card, total;
char answer;
char play_again = 'y';
bool game_over;
while(play_again == 'y')
{
game_over = false;
srand(time(NULL));
card_1 = rand() % 10 +1;
card_2 = rand() % 10 +1;
cout << "First cards: " << card_1 << ", " << card_2 <<endl;
total = card_1 + card_2;
cout << "Total:" << total << endl;
while(!game_over)
{
cout << "Do you want another card? (y/n):"<<endl;
cin >> answer;
if (answer == 'y'){
new_card = rand() % 10 +1;
cout << "Card: "<< new_card <<endl;
total += new_card;
cout << "Total: " << total <<endl;
if (total > 21) {
cout << "Bust" << endl;
game_over = true;
}
} else if(answer == 'n') {
game_over = true;
}
}
cout << "Would you like to play again? (y/n)" <<endl;
cin >> play_again;
}
}