0
class Program
{
    public static void Main()
    {
        double[,, ] stats = new double[3, 2, 10];
        string[] players = new string[3];
        int x, y, z;

        players[0] = "Tom Brady";
        players[1] = "Drew Brees";
        players[2] = "Peyton Manning";

        for (x = 0; x < 3; ++x)
        {
            Console.WriteLine("Enter stats for {0}", players[x]);
            for (y = 0; y < 2; ++y)
            {
                Console.WriteLine("Game {0}", y + 1);
                stats[x, y, z] = ***inputstats(stats[x, y, z])***;
            }
        }
    }
    public static double[] inputstats(double[] methodstats)
    {
        methodstats = new double[10];
        Console.WriteLine("Enter pass attempts: ");
        methodstats[0] = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("Enter completions: ");
        methodstats[1] = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("Enter completion percentage: ");
        methodstats[2] = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("Enter total yards: ");
        methodstats[3] = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("Enter touchdowns: ");
        methodstats[4] = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("Enter interceptions: ");
        methodstats[5] = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("Enter rushing yards: ");
        methodstats[6] = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("Enter rushing touchdowns: ");
        methodstats[7] = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("Enter fumbles: ");
        methodstats[8] = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("Enter QB rating: ");
        methodstats[9] = Convert.ToDouble(Console.ReadLine());
        return methodstats;
    }
}

Here is my code I have so far. Keep in mind that I am VERY beginner. I am trying to create a console that will ask for user input for 3 different players over 2 games. Once I get all the data input by the user, I will go on to add the ability for the user to be prompted to display either the game 1 statline, game 2 statline, or the average of the two games. Right now I'm stuck on just getting the input. I am getting an error where I have bold and italics on the line that the best overload method match has some invalid arguments. What am I messing up here? I'm pretty sure it is in z, but I'm not quite sure how to input it into the third dimension of the array for the 10 stats. Halp!

Joshua Kirk
  • 13
  • 1
  • 3
  • 2
    You should make a class that models a player's statistics and set properties in an instance of that class, rather than passing arrays around. – Daniel Mann Aug 29 '13 at 17:05
  • Create a class and model a Player in that - see http://msdn.microsoft.com/en-us/library/0b0thckt(v=vs.110).aspx for an excellent example and tutorial on how to declare classes – jdphenix Aug 29 '13 at 17:30

2 Answers2

0

You have 2 mismatches on that line:

stats[x, y, z] = inputstats(stats[x, y, z]);

double[] inputstats(double[] methodstats)
{
}

The expression stats[x, y, z] is a single double, not an array. So when you fix the argument error you will get one for the assignment of the return value.
This line would compile:

stats[x, y, z] = Math.Sin(stats[x, y, z]);

because the function is declared as double Sin(double a)

Your input method collects an array of doubles, that is not possible with your current array form. You would have to use a jagged array (array-of-array-of-array:

double[][][] stats = ...
// extra code to create the arrays

inputstats(stats[x][y]);

void inputstats(double[] methodstats)
{
}

But you might as well bite the bullet and write a proper class for your data:

class PlayerStats
{
    public double PassAttempts { get; set; }
    public double Completions { get; set; }
    // etc ...
}
H H
  • 263,252
  • 30
  • 330
  • 514
  • After I posted that I realized that a jagged array would work much better. but instead I took out the method all together and just inserted the data that was in the method, and took out int z. It works exactly like I expected and was easier. Only reason I used a method was that for this assignment I had to also use a method, but I can do that in doing the calculations to build the average of the two games. I appreciate your post it helped a lot! – Joshua Kirk Aug 29 '13 at 17:19
0

A simpler solution would be:

public static void Main()
{
    double[][][] stats = new double[3][2][10];
    string[] players = new string[3];

    players[0] = "Tom Brady";
    players[1] = "Drew Brees";
    players[2] = "Peyton Manning";   

    for (int player = 0; player < 3; ++player)
    {
        Console.WriteLine("Enter stats for {0}", players[ player ]);
        for (int game = 0; game < 2; ++game)
        {
            Console.WriteLine("Game {0}", game + 1);
            stats[player][game] = inputstats();
        }
    }

public static double[] inputstats()
{
    //same code
}

A few notes. I used an array of an array of an array instead of a multidimensional array so that an array can be assigned to stats[][] (More Info Here). Also, you should use more descriptive iterator variables (player and game here) and locally scope them. That is declare them in the for loop declaration. Generally, the more local the scope of a variable, the better.

edit: According to Kevin DiTraglia you can assign an array to [,]. But anyway [][][] is apparently faster and more natural for me coming from Java and C/C++

Community
  • 1
  • 1
clcto
  • 9,530
  • 20
  • 42