write a program that simulates the rolling of two dice. The program should use rand to roll the first die and 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 vary from 2 to 12, with 7 be the most frequent sum and 2 and 12 be the least frequent sums). The following figure shows the 36 possible combinations of the two dice. your program should roll the two dice 1000 times. Use a single subscripted array to tally the numbers of times each possible sum appears. Print the result in a tabular format also determine if the total is reasonable(i.e., there are six ways to roll a 7, so approximately one six of all the rolls should be 7).I
ارجو مساعدتي في هذا البرنامج (ضروري قبل الثلاثاء)
السلام عليكم ورحمة الله وبركاته:
أرجو مساعدتي في البرنامج قبل يوم الثلاثاء ضرووووري...
وجزاكم الله خير..
its easy use srand first then use rand function and define a variable to be the maximum number like
#define A 6
and use the system time to solve the problem of getting the same number while using rand()
#defin N 6 srand( (unsigned)time( NULL ) ); dice_1 = (int)N * rand() / (RAND_MAX); dice_2 = (int)N * rand() / (RAND_MAX);
then u must check that dice_1 and dice_2 does not equal 0 if it is 0
just random it again till its not a 0 cause there is no 0 in a dice
then its easy to add them up and print their value
i apologize i didnt give full code and didnt write in arabic because am at university now
جزاك الله خير v1r05..
مشكووور وما قصرت .. عطيتني لب الحل.
لكن اذا ما عليك كلافه وتقدر تكتب لي الكود كامل يا ليت تكتبه والله يجعله في ميزان حسناتك.
لأنه هو برنامج اضافي مو داخل بالمنهج.
فما عندي اي فكره عنه وخصوصا الـ rand function
والله يعطيك العافية.
هذا الموضوع مغلق.