#1




A program that simulates the rolling of two diceHere is a simple program. Write a program that simulates the rolling of
two dice... Here is the solution out of Deital's manual 3d ed. . This is not compiled code. CPP / C++ / C Code:
The bolded is part of the problem I couldn't figure out and is unimportant for the discussion. Here is a section of the readout. Sum Total Expected Actual 2 996 2.778% 2.767% 3 2015 5.556% 5.597% 4 3005 8.333% 8.347% 5 3965 11.111% 11.014% Now here is where things get wierd. So I decided to compile it. Here is my code: CPP / C++ / C Code:
Here is my partial readout: Sum Total Experimental Prob. 2 950 2.64% 3 1995 5.54% 4 2938 8.16% 5 4086 11.35% Pretty wierd huh ? How can I reconcile this. Is it property of psuedorandom numbers,my code ,probabilty. Looking at the Experimental Prob, the results are pretty close but Totals are pretty far apart for some the scores. If we look at Sum 5 it over a 100 points ! One other question if using a CaseSwitch statement with an array counter, should counts be the same? Ex CPP / C++ / C Code:


#2




Re: what's happening here ?What's weird? What's to reconcile?
Your answers are well within random expectations. Code:
__________________
Definition: Politics Latin, from poly meaning many and tics meaning blood sucking parasites  Tom Smothers 
#3




Re: what's happening here ?No. Some of the data counts just seemed a bit unreasonable.
Thanks. 
#4




Re: what's happening here ?You previously stated that you use whitespace effectively. Did you happen to notice the difference between the book code that you posted (which is copyrighted) and "your" code, which most definitely (notice, no 'a') is NOT particularly whitespace friendly?
If anything, the Deitel (again, no 'a' ...hello, McFly, WAKE UP!) code excessively uses whitespace while your code has no sense of whitespace at all. Here's the deal. The REAL deal. If you do not have the "attention to detail" to even be able to accurately copy the name of the authors whose book you have in your possession, how can we expect anything but a lack of attention to detail in everything else from you? Of course, you're likely to disagree with me. You have demonstrated a limited ability to comprehend the fundamentals of the language without an argument. MxB 
#5




Re: what's happening here ?I will put more white spaces next time and try to make my code more friendly for people to read.
Here is the example of my code with white spaces CPP / C++ / C Code:

#6




Re: what's happening here ?Next Time!
Well if you ain't got the time, what makes you think we do? I'mnottoointerestedintryingtoreadabunchofstuffcram medtogether! Are you? 
#7




Re: what's happening here ?What Howard is trying to say is use better formatting.
__________________
Definition: Politics Latin, from poly meaning many and tics meaning blood sucking parasites  Tom Smothers 
#8




Re: what's happening here ?Quote:
Then why did you attempt to bold it? Oh, well, maybe it's important to others who may be reading this but are too shy to ask. So... CPP / C++ / C Code:
There is no way to get a total of zero. There is no way to get a total of one. Thre is only one way that you can get a total of 2: 11 Here are the two ways that you can get total of 3: 12, 21 Here are the three ways that you can get a total of 4: 13 22 31 Here are the four ways that you can get a total of 5: 14, 23, 32, 41 Here are the five ways that you can get a total of 6: 15, 24, 33, 42, 51 Here are the six ways that you can get a total of 7: 16, 25, 34, 43, 52, 61 Here are the five ways that you can get a total of 8: 26, 35, 44, 53, 62 Here are the four ways that you can get a total of 9: 36, 45, 54, 63 Here are the three ways that you can get a total of 10: 46, 55, 64 Here are the two ways that you can get a total of 11: 56, 65 There is only one way that you can get a total of 12: 66 There are no other possibilities (Unless one of themor, maybe, bothfalls off of the table, in which case my friends in Reno will mockingly shout, "No Dice!") Now do you understand why the array members have the values that are shown? Then for values of j from zero through 12, the probability that a given roll of two fair dice will have a value of j is given by the array element expected[j] divided by 36.0. Now, forget the program for a minute. Suppose I told you that I had rolled a pair of dice 36,000 times and I got the following results: Code:
See how it goes? The expected number of occurrences of a particular value is equal to the number of throws times the probability of the occurrence of that particular value. (Of course we could execute any number of throws, but 36,000 makes expected numbers easy to calculate, right? Didn't even need a calculator, much less a program.) The question is: Were these fair throws? There are statistical methods for testing whether results are consistent (to a certain degree of numerical "confidence") with truly random values of each die that was thrown, but that's another topic. Surely you don't expect that out of 36,000 "random" throws that there will be exactly 1000 snakeeyes and exactly 2000 threes and exactly 3,000 fours, etc., do you? I mean, if the observed numbers were all exactly the same as the statistically expected values, I would suspect that the game was fixed. See Footnote. As for your program: Since its calculations are based on those from the book, I would expect the results to be consistent. Instead of using srand(time(0), use the same fixed number for both programs. For example CPP / C++ / C Code:
Other than a missing semicolon and a missing closing brace, your program has a bug that results in undefined behavior: The dimension of your mySum array should be 13, not 12. There is also a (very minor) bug in your calculations: Your program simulates 36,001 rolls but your percentage calculation has division by 36,000. This results in a very slight bias in your percentages. Quote:
Why the heck would you do the case stuff instead of just using the index? Well, maybe to give you some confidence in your knowledge of program constructs, so, maybe it's worth a little investigation. So... If you do the calculations the same, the results have to be the same, right? So, if your results aren't the same, the calculations weren't the same. The easiest way to compare them is to do the calculations exactly the same: CPP / C++ / C Code:
The sum array will have exactly the same contents as the die_score array. Exactly. Regards, Dave Footnote: Left as exercises for the motivated (and talented and knowledgeable) student (but not necessarily a topic for further discussion on a generic programming assistance forum like this one): What is the probability that, out of 36,000 fair throws, there are exactly 1000 snakeeyes? What is the probability that there are exactly 2000 threes? Etc. Now, what is the probability that there are exactly 1000 snakeeyes and 2000 threes and 3000 fours and etc. In terms of programming: If the pseudorandom numbers have all necessary statistical properties to simulate an unlimited number of throws of two sixsided dice, how many program runs of 36,000 throws would you expect to have to execute before you could reasonably expect to see exactly 1000 snakeeyes? Etc. Last edited by davekw7x : 23Mar2010 at 01:00.

#9




Re: what's happening here ?Quote:
This is not my code: CPP / C++ / C Code:
I went looking on the net for infornation and found what you showed. Here is my code for the outcomes of two die based on dietotal.jpg: I will check later if the table is correct. CPP / C++ / C Code:
7 should be the most displayed number, which did show up when printed out. I then divided expected[i] by 36. Other than the code you show, is what I have in program. That is how I initially solved it. The game would be fixed since the element of randomness was minimized or removed by loading the die. Well my probability and stats rusty and when looking at the totals , the differences between the two methods just freaked me out. 
#10




Re: what's happening here ?Quote:
Quote:
I tried to use a logical narrative to see how I would arrive at the values for the expected[] array. Here's a way, using a program, to see how the values of the expected[] array can be calculated: CPP / C++ / C Code:
Output: Code:
Regards, Dave Last edited by davekw7x : 23Mar2010 at 09:09.

«
Previous Thread

Next Thread
»
Thread Tools  Search this Thread 
Rate This Thread  



Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Memory leak when nothing is happening... How can I even debug this ?  Algar  MS Visual C++ / MFC Forum  10  19Nov2007 08:17 
help not sure wat is happening  saxon  Computer Software Forum  Windows  2  26Mar2006 17:37 
What's happening to nature?  priyanka  Open Discussion Forum  7  30Oct2004 12:58 
Looking like a Google 'DeepCrawl'?  JdS  Search Engine Optimization Forum  13  27Dec2003 02:41 
Operator overloading (not happening)  gmn  C++ Forum  11  30Aug2003 08:18 
Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The
All times are GMT 6. The time now is 08:09.