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
|
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
// int main includes the playGame functions that plays the entire game.
int main () {
int funds, bet, card1, card2, card3;
void playGame(int& funds);
playGame(funds);
}
// playGame includes all of the functions necessary to play.
void playGame(int& funds) {
bool isBetween(int card1, int card2, int card3);
string getCardFace(int cardNum);
string getCardSuit(int cardNum);
int getBet(int& funds, int& bet);
int cardNum, bet;
int card1, card2, card3;
cout << "Enter card number 1: ";
cin >> card1;
cout << "Enter card number 2: ";
cin >> card2;
isBetween(card1, card2, card3);
cout << "Your cards are " << getCardFace(card1) << " of ";
cout << getCardSuit(card1) << " and " << getCardFace(card2);
cout << " of " << getCardSuit(card2) << "." << endl;
cout << "Enter bet: ";
cin >> bet;
getBet(funds, bet);
srand (time(NULL));
card3 = rand() % 51 + 0;
cout << "Card number 3 is " << getCardFace(card3) << " of ";
cout << getCardSuit(card3) << "." << endl;
isBetween(card1, card2, card3);
switch(isBetween(card1, card2, card3)) {
case 0 :
cout << "You lose!" << endl;
funds -= bet;
cout << "You have $" << funds << " remaining." << endl;
break;
case 1:
cout << "You win!" << endl;
funds += bet;
cout << "You have $" << funds << " remaining." << endl;
}
}
// getCardSuit gets the card suit to display.
string getCardSuit(int cardNum){
int suit = cardNum / 13;
if (suit == 0)
return("Hearts");
else if (suit == 1)
return("Diamonds");
else if (suit == 2)
return("Spades");
else if (suit == 3)
return("Clubs");
}
// getCardFace will display and determine the card face.
string getCardFace(int cardNum){
int face = cardNum % 13;
if (face == 0)
return("Ace");
else if (face == 1)
return ("Two");
else if (face == 2)
return ("Three");
else if (face == 3)
return ("Four");
else if (face == 4)
return ("Five");
else if (face == 5)
return ("Six");
else if (face == 6)
return ("Seven");
else if (face == 7)
return ("Eight");
else if (face == 8)
return ("Nine");
else if (face == 9)
return ("Ten");
else if (face == 10)
return ("Jack");
else if (face == 11)
return ("Queen");
else if (face == 12)
return ("King");
}
// This function tells whether the third card will be in between the first and second. If true, will display a 1, if false
// will display a 0.
bool isBetween(int card1, int card2, int card3){
if ((card3 < card2) && (card3 > card1))
return (true);
else
return (false);
}
// Get's the players bet and displays it.
int getBet(int& funds, int& bet){
funds = 1000;
if (bet < 100)
do {
cout << "Bet must be at least $100" << endl;
cout << "Enter bet: ";
cin >> bet;
} while (bet < 100);
else
return (bet);
cout << "Your bet is $" << bet << "." << endl;
}
|