I'm new to coding and just doing it as a hobby and I'm working through some CodeAbbey problems to practice.
I'm trying to take groups of numbers separated by spaces and new lines and populate a multidimensional array so I can perform some math on these numbers. I haven't got to the math part yet and am still trying to get the data into the array.
Sample of the dataset:
5 (this is the number of data sets)
(below are the actual pieces of data)
7899743 906
6574065 -1243290
5441 1320
9965047 86
4781 1934
My code is as follows:
namespace Rounding
{
class Program
{
static void Main(string[] args)
{
// declare variables
// n asks user for number of array columns
// raw takes the numbers seperated by new lines
int n = int.Parse(Console.ReadLine());
string[] raw = Console.ReadLine().Split('\n');
int[,] numbers = new int [n,2];
// loop through raw array and split the numbers and add them to multidimentional array
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 2; j++)
{
numbers [i, j] = Convert.ToInt32(raw[n].Split(' '));
}
}
// display data from multidimentional array (for testing)
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 2; j++)
{
Console.WriteLine(numbers[i,j]);
}
}
}
}
}
The program should wait for the user to input the number of data sets then wait again for the actual data and then use that data to populate the array.
The debug message I get is on numbers [i, j] = Convert.ToInt32(raw[n].Split(' '));
It says
System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'
Any guidance on what I am doing wrong would be appreciated.