I created a 2d array of type string, which stores name, marks of 3 subjects and total marks. I need to display the records on basis of the rank i.e the student with higher total marks should be shown first. How can i achieve this in C#? Please help.....
class Program
{
static void Main(string[] args)
{
int noOfStudents, totalMarks, position = 1;
string studentName, engMarks, mathMarks, computerMarks;
Console.Write("Enter Total Students: ");
noOfStudents = Convert.ToInt32(Console.ReadLine());
string[,] studentInfo = new string[noOfStudents, 5];
studentInformation(studentInfo);
for(int i = 0; i < studentInfo.GetLength(0) + 1; i++)
{
int temp, count = 0;
for(int j = 0; j < studentInfo.GetLength(1); i++)
{
if (int.Parse(studentInfo[i,4]) < int.Parse(studentInfo[i+1, 4]))
{
temp = int.Parse(studentInfo[i, 4]);
studentInfo[i, 4] = studentInfo[i + 1, 4];
studentInfo[i + 1, 4] = temp.ToString();
}
else
{
count++;
}
}
Console.WriteLine("Student Name: {0}, Position: {1}, Total: {2}/300", studentInfo[i,0], position, studentInfo[i, 4]);
position++;
}
Console.ReadKey();
void studentInformation(string[,] a) {
for(int i = 0; i < noOfStudents; i++)
{
Console.Write("Enter Student Name: ");
studentName = Console.ReadLine();
studentInfo[i, 0] = studentName;
Console.Write("Enter English Marks(Out of 100): ");
engMarks = Console.ReadLine();
studentInfo[i, 1] = engMarks;
Console.Write("Enter Maths Marks(Out of 100): ");
mathMarks = Console.ReadLine();
studentInfo[i, 2] = mathMarks;
Console.Write("Enter Computer Marks(Out of 100): ");
computerMarks = Console.ReadLine();
studentInfo[i, 3] = computerMarks;
Console.WriteLine("************************************");
totalMarks = (int.Parse(engMarks) + int.Parse(mathMarks) + int.Parse(computerMarks));
studentInfo[i, 4] = totalMarks.ToString();
}
}
}
}
}