CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Posts
    1

    Angry I need help with this program!!

    I have a program that I need to modify but I am stuck. Here are the terms.

    - Modify the program by inserting a big part into a loop that will play the program over and over and will display a number of times you have played the game.

    - Have the program ask you how many times you want to play the game.
    - Then the program will play the game the number of times you request.
    - Keeping track of the number of times there was a win or loss.
    - Have the program display the percent (%) of times there was a win.
    - The answer should be a little under 50% (about 47%).

    Here is the sample program that I have to go off to include these stipulations above.

    #include <iostream>
    #include <cstdlib>
    #include <ctime>

    using namespace std;

    int rolldice ();

    void main ()
    {
    enum Status {CONTINUE, WON, LOST};
    int Sum, MyPoint;
    Status GameStatus;

    srand(time(0));

    //Roll the dice
    Sum = rolldice();
    cout << "You rolled " << Sum << '.' << endl;

    switch (Sum)
    {
    case 7:
    case 11:
    GameStatus = WON;
    break;
    case 2:
    case 3:
    case 12:
    GameStatus = LOST;
    break;
    default:
    GameStatus = CONTINUE;
    MyPoint = Sum;
    cout << "Point is " << MyPoint << '.' << endl;
    break;
    }

    while (GameStatus == CONTINUE)
    {
    Sum = rolldice();
    cout << "The roll is " << Sum << '.' << endl;
    if (Sum == MyPoint)
    GameStatus = WON;
    else
    if (Sum == 7)
    GameStatus = LOST;

    }

    if (GameStatus == WON)
    cout << "You win the game." << endl;
    else
    cout << "You lose the game." << endl;
    }

    int rolldice ()
    {
    int Die1, Die2;
    int Total;
    Die1 = (rand() % 6) +1;
    Die2 = (rand() % 6) +1;
    Total = Die1 + Die2;
    return Total;
    }


    Can anyone help me out?!

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: I need help with this program!!


  3. #3
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: I need help with this program!!

    You chose an angry face icon for this thread...

    Exactly what are you angry at? Is it your own noobness maybe

    If you want to learn programming, being angry is the worst possible starting point.
    Nobody cares how it works as long as it works

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: I need help with this program!!

    "Have the program ask you how many times you want to play the game. "

    Can you do that?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured