Hello again everyone, working on another assignment for class. My professor teaches us the long way of writing code instead of making it simplified and shorter. Here is the actual assignment and what I have attempted so far. Any help and advice is most GREATLY APPRECIATED.

1. A two-dimensional array for storing the three quiz grades for a class of 5 students; this array must be initialized to the following:
  { { 87, 68, 94 }, { 100, 83, 78 }, { 85, 91, 76 }, { 65, 81, 66 }, { 65, 71, 56 } } 
2. A one-dimensional array for storing the average quiz grade for each student.

Your application should perform the following tasks:

1. Calculate and store the average grade for each student.
2. Print to the console a nicely formatted two-dimensional table with headings listing the student number (0 to 4), the grade for each quiz (Quiz 1, ... Quiz 3), and the average.
3. Bonus: For 2 bonus points, also provide the data structures and processing for storing last names for the students and including these last names in the two-dimensional table printed out on the console


//Two-Dimensional Arrays.cs
//Student Quiz Grades
using System;

class StudentQuizGrades
 {
      static void Main(string[] args)
      {
         //array of student grades
         int[,] average = new int[,] { { 87, 68, 94 }, { 100, 83, 78 }, { 85, 91, 76 }, { 65, 81, 66}, {65, 71, 56 }};
      }

   {
      //output grades array
      OutputGrades();

      Console.WriteLine("\n{0} {1}\n{2} {3}\n", Average));
   }

{
   //Determine average grade per student
   public double GetAverage(int student)

   int amount = grades.GetLength(1); 
   int total = 0; //initialize total

   //sum grades for one student
   for (int exam = 0; exam < amount; exam++)
      total += grades[ student, exam ];


   //return average of grades
   return (double) total / amount;
}

}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

This is a simple exercise.

First of all If you read the assignment you will see:

1. A two-dimensional array for storing the three quiz grades for a class of 5 students; this array must be initialized to the following:
{ { 87, 68, 94 }, { 100, 83, 78 }, { 85, 91, 76 }, { 65, 81, 66 }, { 65, 71, 56 } }
2. A one-dimensional array for storing the average quiz grade for each student.

I only see one Array which isn't even defined correctly.
should be

int[,] average = new int[5,3] { { 87, 68, 94 }, { 100, 83, 78 }, { 85, 91, 76 }, { 65, 81, 66}, {65, 71, 56 }};

once you have corrected your array(s) get back to me if you have further problems.

Please not that no one will do your work for you that is against the Rules.
What I will do is help you help yourself.

Also it would be advisable that the average array be float or decimal.

P.S. use code tagging next time.

Another piece of advice:
Give your variables meaningfull names!
If I read your assignment, I would call the 2D array StudentGrades, instead of average.
The 1D array(wich you have not defined yet) I would call something like AverageStudentGrades.
Good luck!

Comments
Good Practices :)

I only see one Array which isn't even defined correctly.
should be

int[,] average = new int[5,3] { { 87, 68, 94 }, { 100, 83, 78 }, { 85, 91, 76 }, { 65, 81, 66}, {65, 71, 56 }};

Whilst I am a strong advocate of daniwebs homework policy and wholeheartedly agree that we are not here to do the work. I have to point out that the OP has made an effort to start and has asked for advise.
Also, there is nothing wrong with declaring the array the way the OP has. If you are populating it at instantiation then it will be sized according to the values you populate it with (as seen here).

To the OP, finito is right to point out the [code]

[/code] tags. It preserves formatting and makes your code much more readable.

As for your code, you are placing the opening brace BEFORE your method declarations:

{
//output grades array
OutputGrades();

//should be:

//output grades array
private void OutputGrades()
{

You are also creating methods but never calling them. All your Main method does is create your array of scores.
Try examining the problem in pseudocode first. Write in plain english (or whatever happens to be your first language) the steps you need to accomplish in order. This will help you design the flow of your program. I'll start you off:

1.Create array of scores and fill it with values
2.Create array to store average scores
3.Calculate average for each student
i. you fill in
ii. the rest

Also, there is nothing wrong with declaring the array the way the OP has. If you are populating it at instantiation then it will be sized according to the values you populate it with (as seen here).

Thanks for pointing that out, I actually had that doubt and reached that same page but didn't notice that it is possible to instantiate an array in such a fashion in C#.

Here is what I have so far....on my corrections. It is still a work in progress and I plan to fill in brackets.

//Two-Dimensional Arrays.cs
//Student Quiz Grades
using System;

class StudentQuizGrades
{
   static void Main(string[] args)
   {
      //array of student grades
      decimal[,] Quizzes = { { 87, 68, 94 }, { 100, 83, 78 }, { 85, 91, 76 }, { 65, 81, 66 }, { 65, 71, 56 } };
      Quizzes[4, 2];

      //average quiz grade array
      decimal[,] Avergae = {{}, {}, {}, {}, {}};

      //student name array
     string[] Name = new string {{name}, {name}, {name}, {name}, {name}};

      count NumQuiz = 3;
         Decimal total = 0;
     for (student = 0; student < QuizLength; student++)
     {
        for (quizCount = 0; quizCount < NumQuiz; quizCount++)
           total = total + Quiz[student.quizCount];
        Average[student] = total / NumQuiz;
     }
   }
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

I just want to make sure I am on the right track with everything.

kavisg1 please use code tagging.

Select your code and press the CODE Button.

Ok Lets break down what you did.

baby steps.

decimal[,] Quizzes = { { 87, 68, 94 }, { 100, 83, 78 }, { 85, 91, 76 }, { 65, 81, 66 }, { 65, 71, 56 } };
Quizzes[4, 2];

Can you please explain what you did here. I mean do you understand what you did?

Please look at link Ryshad Provided.

decimal[,] Avergae = {{}, {}, {}, {}, {}};

Apart from the spelling mistake can you tell me what type of array this is from the link.

string[] Name = new string {{name}, {name}, {name}, {name}, {name}};

I understand this is to answer the extra credit question but Please leave that till you done with your actual assignment.

Please get back to me with your answers so I/we may help you further. You have more errors but Lets get the arrays corrected first.

:)

Edited 3 Years Ago by Nick Evan: Fixed formatting

Comments
with you on all counts :p

I can honestly say that programming makes my eyes cross and pulsate from the pressure of having to sort it out. I understand the concept of my assignment but I have the hardest time actually putting it in writing and knowing which code to use and where to put it. I get confused on what you can and cannot do and I have been reading different sources concerning arrays and it doesnt really help me understand what I am doing. If someone is able to bring it down to the simplest of terms and help me understand why things are done the way it is and what order it should be done, then that should help me to finish it.

Hmm how about I give a you an example of pseudo code.

Pseudo code is just writing the code in plain English.


give it a try, show me something, and then I/we can discuss what you did correct or wrong.

Everyone's eyes crossed and pulsated when they learned their first computer language.

Just like with spoken languages, its a matter of exposure, repetition, and continued growth until you are aren't thinking about the language, but rather thinking in the language.

That's the difference between a programmer and a coder, to me. A programmer knows how to program in the language ... a coder thinks in the language.

A programmer knows how to program in the language ... a coder thinks in the language.

I don't see your point, coder and programmers are the same thing.

What you may want to say is in companies, the programmers are given detailed functions to write out. All they have to do is follow the outline, where as Solo, you do everything from scratch.

Are referring to that model as a concept of your definition?

I don't see your point, coder and programmers are the same thing.

What you may want to say is in companies, the programmers are given detailed functions to write out. All they have to do is follow the outline, where as Solo, you do everything from scratch.

Are referring to that model as a concept of your definition?

My experience is ... programmers will produce a page or two of code a day. Coders will produce 10+ pages a day.

The point being, the programmers think about the language in every step ... coders are sooo fluent in the language, they don't have to even think about it, it just flows from their finger to the editor.

Programmers write 10-20 lines of code, test it, debug it, rinse and repeat. I've seen coders write 3 or 4 pages of code before they try to build the first time, and then it takes them 10m to fix what are usually just typo's.

Anyone who has worked in programming teams or managed programming teams knows there a huge difference between the "technically competent" (the programmers), and someone who is a master of the language (the coders).

I still don't see the point or relevance in this thread.

ASAIK, in Software Deployment there is a Designer (I forgot the correct term),

The designer will make a detailed layout (pseudo code) of the program and then the programmers will follow this layout.

I have never worked in such an environment, this is what I was told by the head of the Computer Science Department in my university in one of his lectures.

Edited 6 Years Ago by finito: n/a

Here is what I have gotten so far....Is there anything I am missing or that needs to be editted?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
   static void Main(string[] args)
   {
      decimal[,] QuizGrades = { { 87, 68, 94 }, { 100, 83, 78 }, { 85, 91, 76 }, { 65, 81, 66 }, { 65, 71, 56 } };

      //Use constants for student count and quiz count
      const int STUDENTCOUNT = 5;
      const int QUIZCOUNT = 3;

      //Fix declaration of this array
      //need to assign an array object to QuizAverage 
      //decimal[] QuizAverage;
      decimal[] QuizAverage = new decimal[STUDENTCOUNT];

      //There should only be 5 names, not 6
      //string[] StudentNames = { "Smith", "Stava", "Basil", "Little", "Jones", "Anderson" };

      decimal total = 0;
      //The statement below does not make sense to me...
      //int amount = QuizGrades.Length;

      //Write the header of the output table first
      //left align all columns and allow 10 spaces for each
      Console.WriteLine("{0,-10}{1,-10}{2,-10}{3,-10}{4,-10}", "Name", "Quiz 1", "Quiz 2", "Quiz 3", "Average");

      //Use QUIZCOUNT AND STUDENTCPIMT in your loops
      //for (int person = 0; person < QuizGrades.Length; person++)
      for (int person = 0; person < STUDENTCOUNT; person++)
      {
         total = 0;

         //Write statement here to print out the student name

         //         for (int quizCount = 0; quizCount < amount; quizCount++)
         for (int quizCount = 0; quizCount < QUIZCOUNT; quizCount++)
         {
            //Write statement here to print out each quiz grade


            total = total + QuizGrades[person, quizCount];
         }

         //         QuizAverage[person] = total / amount;
         QuizAverage[person] = total / QUIZCOUNT;

         //Write statement here to print out the student average
         
      }

      //      Console.WriteLine("{0,5}{1,10}{2,15}{3,20}{4,20}", "Name", "Quiz 1", "Quiz 2", "Quiz 3", "Average");
      Console.ReadLine();
   }
}

I still don't see the point or relevance in this thread.

ASAIK, in Software Deployment there is a Designer (I forgot the correct term),

The designer will make a detailed layout (pseudo code) of the program and then the programmers will follow this layout.

I have never worked in such an environment, this is what I was told by the head of the Computer Science Department in my university in one of his lectures.

finito ... you need to chill a little man. I was just responding to his stated frustration with learning coding.

Not everything has to be black and white, absolute. Relax a little. :)

I've been in the programming business since 1979 and have been managing programmers since '88, I stand by my statement.

Edited 6 Years Ago by Zinderin: n/a

Our professor has been gracious enough to help us with the assignment some and here are the edits I did to make it look a little better. I am close to debugging it but I get an error on line 38 that the Indexoutofrangeexception was unhandled. I have alot of respect for programmers or anyone that has to work from the cmd line because it is a very intricate job.

using System;

class QuizGrades
{
    static void Main(string[] args)
    {
        decimal[,] QuizGrades = { { 87, 68, 94 }, { 100, 83, 78 }, { 85, 91, 76 }, { 65, 81, 66 }, { 65, 71, 56 } };

        //Student and quiz count constants
        const int STUDENTCOUNT = 5;
        const int QUIZCOUNT = 3;

        //QuizAverage Array 
        decimal[] QuizAverage = new decimal[STUDENTCOUNT];

        //student name array
        string[] StudentNames = { "Johnson", "Wright", "Jenkins", "Thomas", "Simmons",};
        decimal total = 0;

        //The statement below does not make sense to me...
        int amount = QuizGrades.Length;

        //output table
        Console.WriteLine("{0,-10}{1,-10}{2,-10}{3,-10}{4,-10}", "Name", "Quiz 1", "Quiz 2", "Quiz 3", "Average");

        //Use QUIZCOUNT AND STUDENTCPIMT in your loops
        for (int person = 0; person < QuizGrades.Length; person++)
        
        {
            total = 0;

            //prints out student name
            for (int quizCount = 0; quizCount < amount; quizCount++)
            
            {
                //Write statement here to print out each quiz grade
                total = total + QuizGrades[person, quizCount];
            }

            //QuizAverage[person] = total / amount;
            QuizAverage[person] = total / QUIZCOUNT;

            //Write statement here to print out the student average
            Console.WriteLine("{0,5}{1,10}{2,15}{3,20}{4,20}", "Name", "Quiz 1", "Quiz 2", "Quiz 3", "Average");
            Console.ReadLine();
        }

        
    }
}

Zinderin I sincerely I apologize if you take my response as aggressive.


Kav do you know why you are doing this?

for (int person = 0; person < QuizGrades.Length; person++)
        
        {
            total = 0;

            //prints out student name
            for (int quizCount = 0; quizCount < amount; quizCount++)
            
            {
                //Write statement here to print out each quiz grade
                total = total + QuizGrades[person, quizCount];
            }

            //QuizAverage[person] = total / amount;
            QuizAverage[person] = total / QUIZCOUNT;

            //Write statement here to print out the student average
            Console.WriteLine("{0,5}{1,10}{2,15}{3,20}{4,20}", "Name", "Quiz 1", "Quiz 2", "Quiz 3", "Average");
            Console.ReadLine();
        }

It is a double for loop, one is to loop the Height the other the Length of the array.

Think like this.

this is your array

87 | 68 | 94
100 | 83 | 78
 85 | 91 | 76
 65 | 81 | 66
 65 | 71 | 56

and you want the x,y coordinates to locate the different values and since array start with 0 to get 0,0 would mean 87 and 4,2 would be 56.

so when you loop the array you want to loop for the x and y.

do you see the problem?

Hint what is QuizGrades.Length equal to and what is amount equal to?
Index refers to your position in the array. Index out of Range Exception should be clear to you.

Let me know if you don't understand.

Comments
well worded :) Always good to encourage people to find their own errors
This article has been dead for over six months. Start a new discussion instead.