View Single Post
Old 05-03-2005, 07:42 AM   #10 (permalink)
marina
Hottie
 
marina's Avatar
 
Join Date: Apr 2005
Posts: 5
marina is on a distinguished road
I didn't have a chance, until now, to work on my C++. Here is the flowchart of what I'm trying to get.

1. player deposit at least $.25
2. 5 cards are dealt
3. player is asked to throw away up to 3 cards and replaced with new cards
4. winnings are calculated, and user is asked to either cash out or play again
-if play again, go to step 2 to continue playing
5. cash out/no credits left

Here is my code for run_game function:

PHP Code:
void run_game(void)
{
    
// deposit $
    
cout << "Deposit $.25 to start the game" << endl << "$";
    
double money;
    
cin >> money;    

    if(
money .25)
    {
        
cout << "You must deposit at least $.25 to play!" << endl;
        
cout << "Deposit $.25 to start the game" << endl << "$";
        
cin >> money;
    }
        
    
generate_deck();

    
int reply,
        
discarded_card;

//MAIN LOOP
    
int respond 1;

    while(
respond == 1)
    {
        
// deal 5 random cards
        
int hand[5];
        
reset_deck();
        
deal(hand);
        
print_hand (hand);

        for (
int i 03i++)
        {
        
//ask user if they want to get rid of any cards
            
cout << "Would you like to throw away a card?" << endl;
            
cout << "Enter 1 for YES or 2 for NO: ";

            
cin >> reply;

            
//if YES, call get_card to pick out new card
            
if (reply == 1)
            {
                
cout << "Enter one card, 1 to 5, to be discarded: ";
                
cin >> discarded_card;
                
hand[discarded_card 1] = get_card();

                
// if card chosen is not 1 to 5
                
while (discarded_card != && discarded_card != && discarded_card != && discarded_card != && discarded_card != 5)
                {
                    
cout << "Invalid card selection" << endl;
                    
cout << "Enter one card, 1 to 5, to be discarded: ";
                    
cin >> discarded_card;
                    
hand[discarded_card 1] = get_card();
                }
// end while
            
}// end if

            
if (reply != && reply != 2)
            {
                while (
reply !=&& reply != 2)
                {
                    
cout << "Invalid selection!" << endl;
                    
cout << "Would you like to throw away a card?" << endl;
                    
cout << "Enter 1 for yes or 2 for no: ";
                    
cin >> reply;

                    if (
reply == 1)
                    {
                        
cout << "Enter one card, 1 to 5, to be discarded: ";
                        
cin >> discarded_card;
                        
hand[discarded_card 1] = get_card();

                        
// if card chosen is not 1 to 5
                        
while (discarded_card != && discarded_card != && discarded_card != && discarded_card != && discarded_card != 5)
                        {
                            
cout << "Invalid card selection" << endl;
                            
cout << "Enter one card, 1 to 5, to be discarded: ";
                            
cin >> discarded_card;
                            
hand[discarded_card 1] = get_card(); 
                        }
// end while
                    
}// end if
                
}// end while
            
}// end if
            
            // if reply = NO (2): Do nothing

        
}//end for

        
print_hand(hand);

        
// Winnings are calculated
        
if (is_royal_flush(hand) == true)
        {
            
money money 100.00;
            
cout << "You have a royal flush!" << endl << "You won $100!" << endl;
        }
        
        if (
is_straight_flush(hand) == true)
        {
            
money money 12.50;
            
cout << "You have a straight flush!" << endl << "You won $12.50!" << endl;
        }
        
        if (
is_four_of_a_kind(hand) == true)
        {
            
money money 6.25;
            
cout << "You have a a four of a kind!" << endl << "You won $6.25!" << endl;
        }
        
        if (
is_full_house(hand) == true)
        {
            
money money 2.00;
            
cout << "You have a full house!" << endl << "You won $2.00!" << endl;
        }

        if (
is_flush(hand) == true)
        {
            
money money 1.25;
            
cout << "You have a flush!" << endl << "You won $1.25!" << endl;
        }

        if (
is_straight(hand) == true)
        {
            
money money 1.00;
            
cout << "You have a straight!" << endl << "You won $1.00!" << endl;
        }

        if (
is_three_of_a_kind(hand) == true)
        {
            
money money 0.75;
            
cout << "You have a three of a kind!" << endl << "You won $.75!" << endl;
        }
        
        if (
is_two_pair(hand) == true)
        {
            
money money 0.50;
            
cout << "You have two pairs!" << endl << "You won $.50!" << endl;
        }

        if (
is_pair(hand) == true)
        {
            
money money 0.25;
            
cout << "You have a pair!" << endl << "You won $.25!" << endl;
        }

        
// subtract $.25 for playing the game
        
money money 0.25;

        
//Adjust number of credits
        
cout << "Your current cash available is: $" << money << endl;

    if (
money >= 0.25)
    {
        
//ask if user wants to play again
        
cout << "Would you like to play again?" << endl;
        
cout << "Press 1 for YES, and 2 for NO: ";
        
cin >> respond;

        
// if not, Cash out
        
if (respond == 2)
            
cout << "Your cash is: $" << money << endl;

    }
// end if

    
if (money 0.25)
        {
            while(
money 0.25)
            {
                
cout << "Not enough money to continue!" << endl;
                
cout << "To play again, insert more money: $";
                
double added_money;
                
cin >> added_money;
                
money money added_money;
                
cout << "Your current cash is now: $" << money << endl;

                if(
money >= 0.25)
                    
respond 1;
            }
// end while
        
}// end if
    
}// End main while loop
// end run_game 
Any suggestions?

Last edited by marina; 05-09-2005 at 07:10 AM.
marina is offline   Reply With Quote