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
|
#include <ctime>
#include <iostream>
using namespace std;
int humanCards[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int computerCards[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int counter;
bool keepDrawing = true;
void DrawCard() // 0 is human, 1 is computer
{
char yesOrNo;
cout << "Draw a card? (y/n) ";
cin >> yesOrNo;
switch (yesOrNo)
{
case 'y':
cout << "You drew a " << humanCards[counter] << ".\n";
break;
case 'n':
keepDrawing == false;
break;
default:
cout << "Invalid input. Try again.\n";
}
}
void DetermineCards() // Predetermine 12 card numbers for each player
{
srand(time(0));
for (counter = 0; counter < 12; counter++)
{
humanCards[counter] = rand() % 14;
computerCards[counter] = rand() % 14;
}
}
int main()
{
DetermineCards();
cout << "Let's play Blackjack!\n";
do { DrawCard(); counter++; } while (keepDrawing == true);
system("pause>nul");
return 0;
}
|