html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> Joe's Blawg: <span style="color: rgb(204, 0, 0);">Programming Problem, Please help!!!</span>

Joe's Blawg

Nothin' special here. Just ordinary "blawg" conversation from a typical college student striving to glorify Christ with every minute of his life.

Friday, March 31, 2006

Programming Problem, Please help!!!

Here's the instructions for a program I am having trouble with, please help if you can.

Instructions: 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: Since each die can show an integer value will vary from 2 to 12 with 7 being the most frequent sum and 2 and 12 being the least frequent sums.] There are 36 possible combinations of the two dice. Your program should roll the two dice 36,000 times. Use a single-subscripted array to tally the numbers of times each possible sum appears. Print the results in a tabular format. Also, determine if the totals are reasonable; ie., there are six ways to roll a 7, so approximately one sixth of all the rolls should be 7.

Here's what I have so far:


What I am having trouble with is figuring out how to set up arrays so it will display the different odds for each number (eg. 7 being the most frequent, and 2 and 12 being the least frequent). I also cannot figure out how to calculate the percentages for the last two columns (expected and actual), so if anybody can please help with that I'd very much appreciate it.

Btw, if you dont know anything about this, please don't comment with something like "I dont know anything about programming" or "let someone else help you, I'm stumped" or something pointless like that. No offense, but its a little frustrating to get a comment and think someone has a solution to my programming problem, but they are just saying "Its all Greek to me" or something stupid like that. Not to sound mean but this is serious business and I'm kinda worried that I'm not going to be able to figure this out and possibly fail Programming.

comments

5 Comments:

At April 01, 2006 4:14 AM, Blogger X said...

How are you totalling the amount of numbers that you are getting?
You divide that amount over the 36,000 to get your percentage.

What I would do (using C++) is write the random function to go through the loop of 36,000 times and include 13 different loops inside the main loop to add a 1 for everynumber everytime the random function lands on a single number. Something like (and I don't remember if this is the exact code or not but you may get the jest of it)


int a,b,c,d,e,f,g,h,i,j,k,l,m;

int main()
{
startprocess();
}

int startprocess()
{
int x=0;
int z,y,t;

for(x=0;x<36001; //I can't remember the correct code to run the loop and add one to x but I believe it is this// x++)
{
rand(7)=a;//if your random starts from 0 then use 6 and add 1 to it//
rand(7)=b;

a+b=c

if c=2 then
a=a+1;
endif;

//and so on and so forth till you have all thriteen of you numbers where the loop is adding to there totals. Then end your program by having int main() to calculate using your basic math function the average and so forth.//


Now granted, my was longer but it you have any defects or bugs you can find them out sooner. I hope this helped.

 
At April 02, 2006 11:03 PM, Blogger joe4444 said...

Thanks a bunch for your help, but I'm still a little confused on setting up the arrays and on some of the letters you use in your program.

 
At April 03, 2006 1:56 PM, Blogger X said...

Such as?

 
At April 03, 2006 3:35 PM, Blogger joe4444 said...

To get the calculated values for expected and actual. Expected being the percentages each number rolled should land (eg. 1/36 for 2 and 12, 2/36 for 3 and 11, and so on). And actual being the actual percentages of each number that were rolled.

 
At April 03, 2006 4:15 PM, Blogger X said...

You already have the expected so program those in. For the actual, take the amount of times that the dice was rolled for a certain number, and devide it by 36000. That will give you a percentage. That is the number of times you actually got that number.

 

Post a Comment

<< Home