DICE problem!

This is a discussion on DICE problem! within the Game Programming forums, part of the General Programming Boards category; can someone help me with a small problem on a dice game? i have 2 dices or dice!?don't really know ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    479

    Question DICE problem!

    can someone help me with a small problem on a dice
    game?
    i have 2 dices or dice!?don't really know the plural and want to throw them
    once i have thrown them i want to keap one as it is and
    throw the second one again!
    i have started with some code:
    #include<iostream.h>
    #include<stdlib.h>
    #include<time.h>

    int DICE1()
    {
    int nDice=rand()%6+1;
    cout<<nDice;
    return 0;}

    int DICE2()
    {
    int nDice=rand()%6+1;

    cout<<nDice;
    return 0;}
    main()
    {
    srand((unsigned)time(NULL));
    DICE1();
    DICE2();
    return 0;}

    i would apriciate your help!

  2. #2
    barjor
    Guest
    Like this?

    main()
    {
    srand((unsigned)time(NULL));
    DICE1();
    DICE2();
    DICE2();
    return 0;}

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    NO

    THAT would just loop up a nother random number

  4. #4
    Barjor
    Guest
    >>i want to keap one as it is and
    throw the second one again! <<

    So what is it you wanted?

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    ok
    i'll give u an example:

    let's say the first dices number is a 3 and the second a 4
    now i want the player to choose wich dice he wants to keep as it is ex.the first dice which was number 3.
    now the first dice number is still a 3 right?.
    then the player has to throw just dice number 2 not the first dice

    the program will ask:
    cout<<"which dice do u want to keep";
    cin>>thefirst****indice;
    cout<<"u choose thefirstmoth..........**indice";
    dice1=stillasitwas;
    dice2=loopagain;

    you see what i mean now?

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Add two int's to hold the dice returns.
    int iDice[2]={0,0}; or int iDice1=0,iDice2=0;
    Rename the function DICE() from DICE1() and DICE2() as no need to repeat the code.

    add to DICE() a return nDice; instead of return 0;

    after the user has told you which dice they want to keep call DICE() to reroll the other

    iDice[0]=DICE();
    iDice[1]=DICE();
    //find user choice (store as iChoice)
    iDice[0]=iChoice;
    iDice[1]=DICE();

    PS I think the plural IS dice (of die)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    .
    MSVC++ 6.0

  8. #8
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    Why do you have effectively the same function twice?
    Store two numbers:

    Code:
    main ()
    {
       int i;
       int d[2];
    
       for (i = 0; i < 2; i++)
          d [i] = dice ();
    
       d [1] = dice (); 
    }
       
    
    int dice (void)
    {
       return rand () % 6 + 1;
    }
    MSVC++ 6.0

  9. #9
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210

    Die (singular) Dice (plural)

    no no ... You "roll the dice" and you "can't roll a 1 sided die."

    not picking at grammar, just thought you'd like to know
    "The mind, like a parachute, only functions when open."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. Dice Rolling Problem
    By EdSquareCat in forum C++ Programming
    Replies: 3
    Last Post: 05-26-2007, 01:53 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM

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