Thread: please help me out of this c++ program please

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    6

    please help me out of this c++ program please

    write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. The sum of the two values should then be calculated. [note: each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums.]. The program should roll two dice 36,000 times. Use a single-subscripted array to tally the numbers of times each possible sum appears. Print the result in the tabular format. Also, determine if the total are reasonable (i.e., there are six ways to roll 7, so approximately one sixth of all the rolls should be 7).
    ANY ONE PLEASE HELP ME OUT OF THIS C++.......I NEED IMMEDIATE ASSISTANCE. THANKS FOR HELPING.

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    So hmm where's your code?

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    code?

    we'll be willing to help, but not do your homework. please visit these two links

    link one
    link two

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    6

    please do help me

    the main thing is I didnt understand the question and also I m having trouble with C++ array . Please do help me to write this program. I dont need the complete program but if u show me the door I can pass through that. Please.

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    shows filling an array, random numbers, and accessing different portions of an array

    Code:
    #include <iostream.h>
    #include <time.h>
    #include <stdlib.h>
    
    int main (void)
    {
    	srand(time(NULL));
    	int array[10] = { 0 };
    
    	for (int i = 0; i < 10; i++)
    		array[i] = rand() % 6 + 1;
    
    	cout << "The Array\n";
    
    	for (i = 0; i < 10; i++)
    		cout << "     " << array[i] << endl;
    
    	cout << endl;
    
    	return 0;
    }

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    seed rand. num generator ( erm... srand() ring any bells)
    make an array with enough elements for each possible dice score. This is the counter.
    for loop 36000 times ( remember 36000 is bigger than 32767 )
    {
    roll two dice ( use rand()%something+somethingelseyouworkout)
    add 1 to the corresponding array element
    }
    print array
    exit

    now go code it
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    You'll need a function to roll a dice. If you think about it, all that it must do is return an integer from 1-6. (simple enough)

    Now you have a function that will be used for both die.

    Declare an array with a capacity of 12 elements (HINT: an int only goes up to 32767 ( on older compilers, but nevertheless )

    Now all you need to do is roll the die inside a loop, and increment the value for the correct element in the array. ( think a little bit harder )

  8. #8
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    dont need 12 elements only 11. you cant roll a 1 and wasting an element is well just wasteful
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  9. #9
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    >> dont need 12 elements only 11. you cant roll a 1 and wasting an element is well just wasteful

    True. I think that it would be better with 13 ( Yes 13, it's what I meant to say before ). With 13 elements, you'll be able to use the sum of two die in as the index easily.

  10. #10
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    is that worth it to do away with a subtraction my 3 year old daughter could do?
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  11. #11
    Registered User
    Join Date
    Apr 2003
    Posts
    6

    I m dumb in array

    I am really dumb in array chapter.............however I study or try I cant work..... This array will lower my grade. I am unable to work I have no idea what I am suppose to do. ;(

  12. #12
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    well post your effort and we will help fix it. but then again i dont suppose for one minute you have made an effort. I spelt it out almost in words of 1 syllable, jamsan posted some code for you to see how random nums and arrays work. whats the problem?
    laziness?
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  13. #13
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    look ill be slightly lenient.....


    assume unsigned int counter[11]={0}

    for(36000 times)
    {
    ++counter[ (rand()%11+2)-2];
    }

    rand%11 is rand num in range 0-10
    rand%11+2 then is range 2-12

    the -2 makes the dice tally with the array element.

    i.e. num of 2's is in counter[0]
    num of 3's is in counter[1]
    etc.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  14. #14
    Registered User
    Join Date
    Apr 2003
    Posts
    6

    :(

    ok i will try to get it .......... but still this is going to break my brain..........i wused to do other work I dont know why I am sucking in array that badly.

  15. #15
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    that was only shown as an example. You WILL want TWO variables for random numbers to ensure correct distribution as in 2 and 12 coming up much less frequently than 6 or 7
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM