C++ program random number generator need help

This is a discussion on C++ program random number generator need help within the C++ Programming forums, part of the General Programming Boards category; I need a program that can simulate two dice rolling and then add the sum up together. You enter how ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    8

    C++ program random number generator need help

    I need a program that can simulate two dice rolling and then add the sum up together. You enter how many times you roll the dice and then it displays how many times your combined roll is a 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Sounds like homework...

    What is the problem? Show the code you have so far

    Edit:
    Haha, I just saw the other post
    I really wanted to be mean now, but ill be nice. Good luck
    Last edited by h3ro; 10-07-2007 at 02:49 PM.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    using namespace std;

    int main(int argc, char *argv[])
    {int dice1;
    int dice2;
    int dicesum;

    dice1 = rand() % 6 + 1;
    dice2 = rand() % 6 + 1;
    dicesum = dice1 + dice2
    cout << diesum;

    return 0;
    system("PAUSE");
    return EXIT_SUCCESS;

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    There is a few tutorials on loops here, you should check them out. It might be just the thing you need :O

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    i dont know what a loop is

  6. #6
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Thats why you should read the tutorial...

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    just do it for me

  8. #8
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    just do it for me
    Here you go. But I will only do this once,ok?

    Code:
    using namespace std;
    
    int main(int argc, char *argv[])
    {
    
    int dice1;
    int dice2;
    
    loop noOfRolls = 3; // Will make it do it 3 times
    
    int dicesum;
    
    do noOfRolls(3)
    (
    dice1 = rand() &#37; 6 + 1;
    dice2 = rand() % 6 + 1;
    dicesum = dice1 + dice2
    
    cout << diesum;
    ) end noOfRolls(3)
    
    return 0;
    system("PAUSE");
    return EXIT_SUCCESS;
    }

  9. #9
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    Thanks a lot but it does not run

  10. #10
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Maybe you should read the tutorial then, to see why?

  11. #11
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    where is it

  12. #12
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    under the tutorial section i guess?

  13. #13
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    cant find it

  14. #14
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485

  15. #15
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Wow catdieselpow, are you completely helpless? Your entire thread reeks of "I don't want to work, I don't want to think, you do everything for me."
    My best code is written with the delete key.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random number gen & looping probelm :?
    By FoxeySoulSLayer in forum C++ Programming
    Replies: 1
    Last Post: 04-10-2009, 06:44 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  3. Random number + guessing game trouble
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-08-2007, 04:33 AM
  4. Generating a random number?
    By Konspiracy in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2007, 01:33 AM
  5. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 03:40 PM

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