6 Replies - 701 Views - Last Post: 18 April 2012 - 07:48 PM Rate Topic: -----

#1 mskiki14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-April 12

Im having trouble with this problem please help.

Posted 18 April 2012 - 05:40 PM

create a 2D array that holds grades 6 courses for 20 students. Generate random grades. compute the average for each student. compute the average for each course. Display all grades and averages in a table. What am i doing wrong?
class Program
    {
        static void Main(string[] args)
        {
            Random rand = new Random;
            int [,] grades = new int [6,20];
            for (int x = 0; x < grades.GetLength (0); ++x)
            {
                for (int y = 0; y < grades.GetLength (1); ++y);
                {
                    grades [x, y] = 70 + rand.Next () % 31;
                }
            }

            int [] Average = new int [20];
            Console.WriteLine("Grade summary: r\n\");
                Console.WriteLine("Student  1  2  3  4  5  6  7  8");
            Console.WriteLine("------------------------------------------------------------------------")

                for (int x = 0; x < grades .GetLength  (0); ++x)
                {
                    Console.Write("Math" + (x +1) + " ");
                    for (int y = 0; y < grades .GetLength(1); ++y)
                    {
                        Average [y] += grades [x, y];
                        Console.write("{0, 4: D}", grades [x, y]);
                    }
                    Console.WriteLine();

                }
            Console.Write("\r\n avg. ");
            foreach (int avg in Average)
            {
                Console.Write("{0,4:D}", Average / grades.GetLength (0));
            }
            Console.WriteLine();
        }
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Im having trouble with this problem please help.

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: Im having trouble with this problem please help.

Posted 18 April 2012 - 05:48 PM

There are more than 500,000 users on the DIC. Can you imagine if they all started threads as "Problem" ? Please use meaningful titles so the people with the most knowledge in your area are drawn to your question. This also helps people later using search engines to find they help they need.

Quote

What am i doing wrong?

What problems are you having? We're not telepathic. You have to actually tell us what's happening on your end, and how it is different than what you expected... error messages... Crashing... Wrong results...
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Im having trouble with this problem please help.

Posted 18 April 2012 - 06:11 PM

And to add to what tlhIn`toq posted, we are not here to do your homework. We are happy to help you get past problems you are having, but we will not give you the code. You need to tell us what your problem is.
Was This Post Helpful? 0
  • +
  • -

#4 mskiki14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-April 12

Re: Im having trouble with this problem please help.

Posted 18 April 2012 - 06:55 PM

Well I'll tell you what's happening on my end it won't run! Does that clarify things for you?
Was This Post Helpful? 0
  • +
  • -

#5 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4490
  • View blog
  • Posts: 7,822
  • Joined: 08-June 10

Re: Im having trouble with this problem please help.

Posted 18 April 2012 - 07:14 PM

Not in the slightest. We're not being mean or anything...you have to give to get. You have to tell us specifically what's happening, as in...does it crash? Does it run? Does it give you any output? Is the output different than what you want? How's it different? If there's an exception, what's the line number? What's the exception text?

See what we're getting at here?
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: Im having trouble with this problem please help.

Posted 18 April 2012 - 07:41 PM

View Postmskiki14, on 18 April 2012 - 07:55 PM, said:

Well I'll tell you what's happening on my end it won't run! Does that clarify things for you?


It clarifies that your attitude towards those you are asking for help isn't the greatest, and falling dangerously close to this article. You're tired. You're frustrated. I get that. But remember, you're not frustrated WITH US. So don't take it out on us.

Next: Visual Studio is showing you and telling you of all the things you need to fix. So look and fix them.
Do you see all the red lines under parts of your code: Those are problems. If you hover over them it will TELL you what's wrong with them.

Attached Image

And there is a list at the bottom if you try to compile.

Attached Image



mskiki14: What this shows us is that you aren't familiar with breakpoints and how to debug your own code. Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.


See FAQ # 2. (Click the SHOW button below)


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated Apr 2012
Spoiler



Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: Im having trouble with this problem please help.

Posted 18 April 2012 - 07:48 PM

just to get you going on one of your bugs...

You have to pay attention to the examples in your textbook...
Its not r\n\"
That reads as r{escape n}{escape quote}
You want {escape r}{escape n} quote so \r\n"
That would be {return}{NewLine} end-quote

The compiler will give you what you tell it, not what you meant. Details are important.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1