Thread: 2nd day programming

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    34

    2nd day programming

    Hey all,
    I was interested in learning how to program and one of my friends had me do a few exersizes.... yet i am completley lost. he wants me to do these things using arrays and loops:

    write a program that will simulate the rolling of two dice in 6000 trials:

    1. use a pair of arrays to store the trial results (got it)
    2. print a table of results that shows the number of times each possible total of the two dice was obtained. label row and column
    What? i cant get this.... help
    3. use a third arry to store the info required
    4. display som of 2 at the top and sum 12 at the bottom
    5.each row in your chart should show the # of dots, the # of times that # of dots came up (frequency), and the proportion of total trials on which that number of dots came up (frequency/total trials) as a float.
    6.use a fourth array to record the information required for this table
    7. display double 6's at the top row and double 1's at the bottom


    AHHHHH!!! i would ask my friend, yet he is out of town.....this is what i have so far (not much hehe):

    Code:
    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    
    #define ROLLS 10
    
    void main (void)
    {
    	int dieone [ROLLS];
    	int dietwo [ROLLS];
    	int i;
    	int sum;
    	
    	
    
    	srand((int)time(NULL));
    	
    	
    	printf("Dieone     Dietwo     Sum\n");
    	printf("-------------------------");
    		
    	
    	for(i=0;i<ROLLS;i++)
    	    {
    		dieone[i ]=rand()%6+1;
    		dietwo[i ]=rand()%6+1;
    		sum= dieone[i ] + dietwo[i ];
    				
    				
    			
            printf("\n%i          %i          %i\n",dieone[ i],dietwo[i ],sum);
    
    	     }
    
    	
    }
    Any help or anything would be greatly appreciated.....man this must sound so dumb.... well, its only my 2nd day so HELP!
    thanks alot


    Code tags added by Kermi3, I also inserted spaces in all [I ] so that they appear in teh code instead of causing italics.

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you


    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    {
    cout << "No code tags are bad";
    }

    With Code Tags:
    Code:
    for(int i=0;i<5;i++)
    {
         cout << "This code is easy to read";
    }
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [ code ] at the beginning of your code and [ /code ] at the end, only without the spaces. More information on code tags may be found at the link in my signature. Any further questions or ways I can help please feel free to PM me.

    And good luck learning, hope your friend returns soon instead of ditching you
    Kermi3
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    34

    Smile

    ok sorry ---- will do next time.... thanks

  4. #4
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    No problem, it's a very common mistake.

    *in bad arnould voice*"They don't call the CodeTagerator for nothin*
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You're trying to do too much, too fast. This program is far too complicated for someone only two days into C. I would recommend starting simpler, but if you must finish this program, take the requirements and write a short program to test each bit. Break the big problem up into itty bitty problems that you can solve, then you can use the knowledge gained to write more complicated examples and plug them together to get the finished program.

    >void main (void)
    I'll nip this one right now, never use void main, it invalidates your entire program with undefined behavior. Use this tag for main:

    int main ( void )

    >*in bad arnould voice*"They don't call the CodeTagerator for nothin*
    CodeTagerator? I called you the Code Tag Nazi.

    -Prelude
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    34
    sweet, ok thanks guys.... just confused about how i can do #2 on the list above, i dont know how i could display the results of the trials.... whatever... thanks guys..

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: 2nd day programming

    2. print a table of results that shows the number of times each possible total of the two dice was obtained. label row and column
    What? i cant get this.... help
    Figure out how many combinations there are for the dice. For example, two 4-sided dice have the following combinations:

    1-1 = 2
    1-2 = 3
    1-3 = 4
    1-4 = 5
    2-1 = 3
    ...
    4-4 = 8

    So we have a range of 2 to 8, or seven possible totals.

    3. use a third arry to store the info required
    So use an array to store the sums. IE: Each time the total of say "3" comes up, increment that slot in the array.

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User
    Join Date
    Oct 2002
    Posts
    34
    thanks quzah, this is what i have so far.....
    Code:
    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    
    #define ROLLS 10
    
    main()
    {
    	int dieone [ROLLS];
    	int dietwo [ROLLS];
    	int i;
    	int sum;
    	int table1 [ROLLS];
    
    
    	srand((int)time(NULL));
    	
    	
    	printf("Sum        Possible combinations\n");
    	printf("-------------------------------\n");
    		
    	
    	for(i=0;i<ROLLS;i++)
    		{
    			dieone[i]=rand()%6+1;
    			dietwo[i]=rand()%6+1;
    			sum= dieone[i] + dietwo[i];
    			
    			printf("\n\n%i           ",sum);	
    				if(sum==7)
    				{
    					printf("1+6 2+5 3+4 4+3 5+2 6+1");
    			
    				}
    				else if(sum==2)
    				{
    					printf("1+1");
    				}
    				else if(sum==3)
    				{
    					printf("1+2 2+1");
    				}
    				else if(sum==4)
    				{
    					printf("3+1 2+2 1+3");
    				}
    				else if(sum==5)
    				{
    					printf("1+4 2+3 3+2 4+1");
    				}
    				else if(sum==6)
    				{
    					printf("1+5 2+4 3+3 4+2 5+1");
    				}
    				else if(sum==8)
    				{
    					printf("2+6, 3+5 4+4 5+3 6+2");
    				}
    				else if(sum==9)
    				{
    					printf("3+6 4+5 5+4 6+3");
    				}
    				else if(sum==10)
    				{
    					printf("4+6 5+5 6+4");
    				}
    				else if(sum==11)
    				{
    					printf("6+5 5+6");
    				}
    				else if(sum==12)
    				{
    					printf("6+6");
    				}
    		}
    	
    }
    but how do i store these into arrays? i dont know how i would store the possible combination values in an array....it... thanks guys. Oh yeah and i dont know the rest either!!! yay!!!
    And this is a random output:

    Sum Possible combinations
    ---------------------------------------


    11 6+5 5+6

    4 3+1 2+2 1+3

    5 1+4 2+3 3+2 4+1

    9 3+6 4+5 5+4 6+3

    8 2+6, 3+5 4+4 5+3 6+2

    8 2+6, 3+5 4+4 5+3 6+2

    8 2+6, 3+5 4+4 5+3 6+2

    6 1+5 2+4 3+3 4+2 5+1

    10 4+6 5+5 6+4

    10 4+6 5+5 6+4

    OH man im in way over my head, i just want to try to impress the slacker who left this with me..... hah
    Last edited by lakai02; 10-02-2002 at 08:54 PM.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You're over complicating:

    1 + 1 = 2

    Every time the total is 2, do this:

    int diceTotals[SOME_SIZE];

    diceTotals[0]++;

    This increments the total in the array "diceTotals" slot 0 by one place.

    Every time the total is 3, do:

    diceTotals[1]++;

    You can even speed this up, if you think about how this works out:

    Since the minimum total is 2, and the minimum array cell is 0, the difference in the actual amount and the cell it fits in is 2. Thus, you can simplify this by going:

    diceTotals[ totalForThisRoll - 2 ]++;

    Assuming that the total for a single roll of the dice is stored in a variable called "totalForThisRoll", you can subtract 2, and have it correctly increment the correct cell.

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Registered User
    Join Date
    Oct 2002
    Posts
    3

    Question

    Prelude said:

    This program is far too complicated for someone only two days into C. I would recommend starting simpler
    I agree, but that's because I'm just trying to start programming myself. From the research I've been doing tonight, I'm pretty overwhelmed. I'm not even sure where to start, honestly. Is C# different from straight C? Is it a precursor to C++ or a sister language? Where do I get the basic of basics on programming, assuming I already am familiar with Basic?
    I can't seem to find anything that'll explain the nuts and bolts like I'm a four year-old.

    Anyway, if anyone has anything they can offer for that problem, I'd appreciate it. I know you're thinking something like, "Hey, if you don't know ANYTHING about it, go enroll in a class or take up accounting." But, there's got to be a way that people start from scratch and want to someday hit the C++ straight.

  11. #11
    Registered User
    Join Date
    Sep 2002
    Posts
    5

    Thumbs up book

    I can't seem to find anything that'll explain the nuts and bolts like I'm a four year-old.
    I got a book called The Absolute Beginers Guide to C. It helped me a lot since i had no programming knowlage. Try that book. It'll talk to you like a 4 year old.

  12. #12
    Registered User
    Join Date
    Oct 2002
    Posts
    3
    Thank you Sec, I'll see if the local library has that one. I also plan on trying to find a good deal on a full-blown Manual, along with the proper software, but for now I'm trying to see if I can get in some of the basics so I can catch up with this "second day" stuff.

    Any resources you know of online for just starting out?

  13. #13
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    Check out other threads here. Others have had the same question.

    Anyway, if anyone has anything they can offer for that problem, I'd appreciate it. I know you're thinking something like, "Hey, if you don't know ANYTHING about it, go enroll in a class or take up accounting." But, there's got to be a way that people start from scratch and want to someday hit the C++ straight.
    Yes, I agree-but not all people are cut out for programming- it takes - problem solving, persistence and especially PATIENTICE (sp). If you can do this- than go for it- otherwise accounting is a good degree.

    Mr. C.

  14. #14
    Registered User
    Join Date
    Oct 2002
    Posts
    3
    Yes, thank you. I've done that, and I got directed over to www.gamedev.net, and I've been reading on that site for the past few hours, but I thought a more human answer might offer some better insight. Thanks for your help folks!

  15. #15
    Registered User
    Join Date
    Sep 2002
    Posts
    137
    Sams teach yourself C in 24hrs is a good book. I know its gimmick ( in 24hrs ) is corny but it explains most stuff in a very good way. Check it out, its helped me become competant with C and I've never taken any form of computer classes ( chemistry's my niche )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2 Noobish Questions from a 2nd Day Learner
    By Bucket in forum C++ Programming
    Replies: 18
    Last Post: 08-25-2006, 01:20 PM
  2. Should I learn a FULL language first?
    By Raeliean in forum Game Programming
    Replies: 8
    Last Post: 07-16-2005, 06:59 PM
  3. error with code
    By duffy in forum C Programming
    Replies: 8
    Last Post: 10-22-2002, 09:45 PM
  4. debug program
    By new_c in forum C Programming
    Replies: 3
    Last Post: 03-18-2002, 11:50 PM
  5. Simplified code
    By soonerfan in forum C Programming
    Replies: 2
    Last Post: 12-05-2001, 03:50 PM