Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHerman Vicens
12,540 PointsDon't know how to return the results. The array is not passing...
I am getting the TreeHouse " BuildMultiplicationTable returned null" error and I've tried putting [], and [][], and many other creative ways but keep getting the error. From the Console.Write I can tell that I am getting the desired results. But I don't know how to pass them.
using System;
namespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static int[][] BuildMultiplicationTable(int maxFactor)
{
int[][] results = new int[100][];
for(int x=0 ; x<maxFactor ; x++)
{
results[x] = new int[maxFactor];
for(int y=0 ; y<maxFactor ; y++)
{
results[x][y] = x*y;
Console.Write(" results[" + x + "][" + y +"] = " + results[x][y]);
}
Console.WriteLine();
}
return results;
}
}
}
3 Answers
Steven Parker
231,198 PointsYou're pretty close.
Here's a hint: the size of the result table should be maxFactor+1 in both dimensions.
Herman Vicens
12,540 PointsThank you Steven. I tried that and gives me an index out of bounds message. I am printing the correct amount of numbers with the Console.Write so in my opinion, the program is doing what it is suposed to. But for some reason, the return statement at the end of the method is not returning the values of the array. Any idea why?
Herman Vicens
12,540 PointsI'm sorry Steven. You were right. I've overlooked the +1 in the instanciation of the second dimention and there is were I was getting the out of bounds message. I fixed that but now I am getting the "you should be getting 6 colums and 6 rows." and that is exactly what I am displayng with the Console.Write statement. Still stuck!! Thanks,
Steven Parker
231,198 PointsWhen you expanded your dimensions, did you also expand your loops to fill them? If that's not it, perhaps you could show the whole code as it is now.