Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Homework Help c#  (Read 4251 times)

0 Members and 1 Guest are viewing this topic.

reaper2191

    Topic Starter


    Rookie

    • Experience: Experienced
    • OS: Windows 7
    Homework Help c#
    « on: January 19, 2014, 08:23:24 AM »
    Okay, so I havent taken c# in over a year and a half and im really no good at it. Im not really looking for a solution just ideas and some syntax error help.
    Heres what I am trying to do:
    Write a C# program to simulate the drawing from a deck of 52 porker cards valued from 1 to 13 with 4 suits.  One round of drawing consists of randomly pull any 4 cards from the 52-card deck. Therefore, the same card cannot appeared more than once.  The program will perform 10,000 rounds of drawing and tallying the frequencies of the following possible results for the 4 cards pulled: (a)the 4 cards are having the same suit, (b)the 4 cards are from the 4 different suits, (c)the 4 cards are having the same value, (d)3 cards have the same value, (e)exactly 2 different pairs of 2 same-value cards, and (f)only 2 cards have the same value. Notice that (b) may occured together with (c) - (f).

    This is what I have so far:
    using System;

    namespace ConsoleApplication3
    {

        class Program
        {
            int[] ranArr = new int[4];

            static int GenerateRandomNum()
            {
                int cleanRandNum;
                Random ran = new Random();
                cleanRandNum = ran.Next(1, 53);

                return cleanRandNum;
            }
            static void Main(string[] args)
            {



                int[] crdv = new int[4]; //1-13

                int[] crds = new int[4];//1-4


                int idx, randNum;

                //Draw 4 cards

                for (idx = 0; idx < crdv.Length; idx++)
                {
                    //randNum = ran.Next(1, 53);



                    Console.Write(randNum + ", "); //Getting a syntax error for this int randNum and the one below. Use of unassigned local variable 'randNum'

                    crdv[idx] = randNum % 13; //Remander value     Heart = 1, Spades = 2, Diamonds = 3, Clubs = 4
                    if (crdv[idx] != 0)
                        crds[idx] = randNum / 13 + 1;
                    else crds[idx] = randNum / 13;
                    if (crdv[idx] == 0) crdv[idx] = 13;
                   
                    //crdv[idx] = ran.Next(1, 13);//Card values Ace-King
                    //crds[idx] = ran.Next(1, 5);//Card Suits (H,C,S,D)

                }

                // Array.Sort(crdv);//Sorts values

                // Array.Sort(crds);//Sorts Suits

                foreach (int val in crdv)
                    Console.Write(val + ", ");

                Console.WriteLine();



                foreach (int suit in crds)
                    Console.Write(suit + ", "); //Spade=1,Hearts=2,Clubs=3,Diamonds=4

                Console.Read();

            }

        }

    }

    From some lessons I took online at the MS C# academy, they say to try to read it like a paragraph. The thing is that Im not really understanding what I am doing lol. The program above is the assignment we have been working on in class. I just need to know I am heading in the right direction and if not where to fix it and how. The commented out section is what we started with before adding other stuff in. I just commented those out so I wouldnt lose them since the program ran with them.

    Thanks for any and all help!