Im about to trow myself from the window..

This is a discussion on Im about to trow myself from the window.. within the C++ Programming forums, part of the General Programming Boards category; Its been 3 long days.. and still i cannot make this program work.. if you still care about my life ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    9

    Angry Im about to trow myself from the window..

    Its been 3 long days.. and still i cannot make this program work..
    if you still care about my life give me a hand..

    in the game you enter the bet amount (all the money you have) and from there you keep betting until you ran out of money, when that happens it has to prompt you if you want to play again, if you do, it has to loop back to the beginning where it ask you for the bet amount(bettotal).

    THANK YOU ALL FOR YOUR HELP>>>
    ------------------------------------------------------------------------------------


    #include <iostream.h>
    #include <cstdlib>
    #include <ctime>

    class Craps
    {
    private:
    int sum, myPoint, die1, die2, workSum;
    double bet, bettotal;

    public:
    int rollDice(); // function prototype
    void internalGame();

    };
    //---------------------------------------------------------------------------------
    int Craps::rollDice()
    {


    die1 = 1 + rand() % 6;
    die2 = 1 + rand() % 6;
    workSum = die1 + die2;
    cout << "Player rolled " << die1 << " + " << die2
    << " = " << workSum << endl;

    return workSum;
    }

    //---------------------------------------------------------------------------------
    void Craps::internalGame()
    {


    cout<<"\a--------\a--------------------\a--------------\a"<<endl;
    cout<<"Enter the amount you have available to play: ";
    cin>>bettotal;
    cout<<"\n";

    do{

    cout<<"Enter the amount you want to bet for this play: "<<endl;
    cin>>bet;

    if (bet>bettotal)
    {
    cout<<"you cannot bet more than you have, please enter again the bet amount: "<<endl;
    cin>>bet;

    }




    enum Status { CONTINUE, WON, LOST };
    Status gameStatus;

    srand( time( 0 ) );
    sum = rollDice(); // first roll of the dice

    switch ( sum ) {
    case 7:
    case 11: // win on first roll
    gameStatus = WON;

    break;
    case 2:
    case 3:
    case 12: // lose on first roll
    gameStatus = LOST;
    break;
    default: // remember point
    gameStatus = CONTINUE;
    myPoint = sum;
    cout << "Point is " << myPoint << endl;
    break; // optional
    }

    while ( gameStatus == CONTINUE ) // keep rolling
    {
    sum = rollDice();


    if ( sum == myPoint ) // win by making point


    gameStatus = WON;

    { if ( sum == 7 ) // lose by rolling 7


    { gameStatus = LOST;
    cout<<"\nYou lost the amount of your bet $"<<bet<<endl;
    bettotal=(bettotal-bet);
    cout<<"now you have $"<<bettotal<<" to play: ";}

    }
    if (bettotal<=0)
    {cout<<"Sorry you have lost all of your money"<<endl;
    }
    }

    if ( gameStatus == WON )
    {
    cout << "Player wins\n";
    cout<<"\nYou receive your bet: $"<<bet<<" plus your the amount you won $"<< bet<<"\n";
    cout<<"it's a total of $"<<bettotal+bet<<" available to play \n";
    bettotal=bet*2;

    }

    }
    while (bettotal>0);


    }


    //--------------------------------------------------------------------------------
    int main()
    {
    char playagain;
    do{
    Craps Execution;


    Execution.internalGame();
    Execution.rollDice();
    cout<<"You lost all of your money\n";
    cout<<"do you want to play again? Y or N\n";

    }
    while (playagain='Y');
    return 0;
    }

    //end
    ------------------------------------------------------------------------------------


  2. #2
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    169
    Where does playagain get set to a value!

    It's not initialised to anything and never set to Y or N. Thats why it exits the do while loop.

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    You need to add a cin statement at the end of your while loop to get whether the user wants to play again.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    moeniareply
    Guest
    i added the cin statement, but still, this is what happens when you execute it.

    output


    ------------------------------------------
    Enter the amount you have available to play: 56

    Enter the amount you want to bet for this play:
    23
    Player rolled 5 + 1 = 6
    Point is 6
    Player rolled 6 + 3 = 9
    Player rolled 5 + 5 = 10
    Player rolled 2 + 4 = 6
    Player wins

    You receive your bet: $23 plus your the amount you won $23
    it's a total of $79 available to play
    Enter the amount you want to bet for this play:
    78
    you cannot bet more than you have, please enter again the bet amount:
    78
    Player rolled 4 + 2 = 6
    Point is 6
    Player rolled 1 + 6 = 7

    You lost the amount of your bet $78
    now you have $-32 to play: Sorry you have lost all of your money
    Player rolled 6 + 2 = 8
    You lost all of your money
    do you want to play again? Y or N
    --------------------------------------------------------------------------
    how can i update bettotal everytime you win or lose, and why it perform the same action twice

    now you have $-32 to play: Sorry you have lost all of your money
    Player rolled 6 + 2 = 8 <<<<<----------------it should not show this

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 07:14 AM
  3. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  4. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21