int main ()
{
int loop=0;
int bet;
int mode = MENU;
int cards[53];
int i;
int suitvalue = 1;
int value = 0;
time_t t;
time(&t);
srand(t);
int cardnum = 1;
int player_card [11];
int dealer_card [11];
switch(mode) // main menu selection switch
{
case 1: game_setup_m();
break;
case 2: rules();
break;
case 3: loop=exit();
if(loop==0)
mode=main_menu();
break;
}
}
}
int main_menu(void) // mode for the main menu
{
int exit1 = 0;
int choice;
do
{
system("CLS"); // clears the screen
cout << "\n \3 \4 BLACKJACK \5 \6 \n"; //main menu layout
cout << " _________________ \n\n";
cout << " [1] - Play\n";
cout << " [2] - Rules\n";
cout << " [3] - Quit\n\n Option: "<<endl;
cin >> choice;
cin.clear();
cin.ignore(INT_MAX,'\n');
if( (choice >0) && (choice<4)) // if choice is 1,2 or 3 go to selection switch
{
exit1=1;
}
else // if not then stay in the loop
{
exit1=0;
}
}
while(0 == exit1);
return choice;
}
void game_setup_m(void) // initialises the game
{
shuffle(); //shuffles deck
bank = 1000; //bank default
current_card = 0; //reset current card
play();
}
void play(void)
{
system ("CLS");
cout << "\n \3 \4 BLACKJACK \5 \6 \n _________________ \n\nYou Have a Balance of ";
cout << bank << endl;
cout << "\nHow much would you like to bet?\n\nBet : ";
cin >> bet;
cout << endl;
bet_m();
}
void bet_m(void)
{
if (bank < 1)
{
cout << "No money left, better luck next time";
system("PAUSE");
main_menu();
}
cout << "Your Cards = " ;
switch(player_card[0].number)
{
case 1:
cout << "A";
break;
case 11:
cout << "J";
break;
case 12:
cout << "Q";
break;
case 13:
cout << "K";
break;
default:
cout << player_card [0].number;
}
switch(player_card[0].suit)
{
case 1:
cout << "\6";
break;
case 2:
cout << "\5";
break;
case 3:
cout << "\4";
break;
case 4:
cout << "\3";
break;
default:
break;
}
//players shown with total
//one of dealers shown
//hit or stick
decision_m();
}
void decision_m (void)
{
char decision;
cout << "\n\nWould you like to [H]it or [S]tick?\n\n";
cin >> decision;
switch (decision)
{
case 'h':
case 'H':
decision_hit();
case 's':
case 'S':
decision_stick();
//default:
// cout << "\nInvalid Choice\n";
// decision_m();
}
}
void decision_hit(void)
{
cout << "hit";
system ("PAUSE");
//deal new card
//new total
// if new total > 21 outcome (dealer)
//decision_m();
}
void decision_stick(void)
{
cout << "stick";
system ("PAUSE");
//if dealer < 17 deal new card to him
// show totals
//if dealer > player, dealer wins : goto dealer wins
//else player > dealer player wins : goto player wins
//else player = dealer tie: goto tie
}
void outcome_dealer(void)
{
int input;
(bank = bank - bet);
cout << "Dealer Wins";
if (bank == 0)
{
cout << "\nYou are out of Money/nGame Over\nWould you like to play again\n[y] [n]?";
cin >> input;
switch (input)
{
case 'y':
case 'Y':
game_setup_m();
case 'n':
case 'N':
exit();
//default:
// if any other key is selected (not n or y) please select again
}
}
else if (bank != 0)
{
cout << "\nDo you want to deal the next hand?";
cin >> input;
switch (input)
{
case 'y':
case 'Y':
play ();
case 'n':
case 'N':
main_menu();
//default:
// if any other key is selected (not n or y) please select again
}
}
}
void outcome_player(void)
{
int input;
//(bank = bank + bet)
cout << "Player Wins";
cout << "\nDo you want to deal the next hand?";
cin >> input;
switch (input)
{
case 'y':
case 'Y':
play ();
case 'n':
case 'N':
main_menu();
//default:
// if any other key is selected (not n or y) please select again
}
}
void outcome_tie(void)
{
int input;
cout << "Tie";
cout << "\nDo you want to deal the next hand?";
cin >> input;
switch (input)
{
case 'y':
case 'Y':
play ();
case 'n':
case 'N':
main_menu();
//default:
// if any other key is selected (not n or y) please select again
}
}
void rules(void)
{
system ("CLS");
cout << "\n \3 \4 BLACKJACK \5 \6 \n _________________ \n\ndisplay rules here\n\n";
cout<<"Press Enter to Return to Main Menu\n"<<endl;
while(cin.get() != '\n');
}
int exit(void)
{
char quit;
int exit2=0;
system ("CLS");
cout << "Are You Sure?\n\n[Y]es [N]o\n\n Option: "<<endl;
cin >> quit;
cin.clear();
cin.ignore(INT_MAX,'\n');
if (quit == 'y' || quit == 'Y')
{
exit2=1;
}
else
{
exit2=0;
//main_menu();
}
return exit2;
}
void shuffle(void)
{
int ii = 0;
int card_dealt=0;
int card_ok= 0;
s_cards swap_card;
You had an issue with not setting the card_set correctly and I changed the deal to work, I think.
I couldn't get the suits to work, so I just used H (heart), S (spade), D (diamond), C (clover).
I see that you are still working on this, so I hope this helps you get further.