I am trying to build a code that outputs user input a certain way. I need to take user input to store 10 statistics for 3 players over 2 games, and then have the code ask the user which player they would like to see. Instead of showing the stats for the two games though, I need to just display the average. I'm having trouble understanding the concept of how to take the numbers that I've inputted and pull them out to an average. In my code below I have it set to display what I entered for game 1, but need it to spit out the average of the two games instead. Everything else in my code is working exactly like I want it to and as it should. I also have to create a method to do the calculations...
If anyone can give me a hand or at least point me in the right direction, I would truly appreciate it!

I have also commented out a few spots to leave obvious comments, but I did comment out a large section of data that the user needed to input just for the sake of saving time while testing.

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

namespace Final
{
class FinalProgram
{
public static void Main()
{
//Declaring Arrays for the players, games/avg, and stats.
double[, ,] stats = new double[3, 2, 10];
string[] players = new string[3];
int x, y;

//Here is my Pre-set Array
players[1] = "Drew Brees";
players[2] = "Peyton Manning";
//Here starts my loops that will ask for first players stats for game 1 first, then loop to game 2. After that finishes it will loop to player 2, etc.
for (x = 0; x < 3; ++x)
{
Console.WriteLine("Enter stats for {0}", players[x]);
for (y = 0; y < 2; ++y)
{
//Here starts my writeable array. This was to save from having to ask the question about stats 60 times in code.
Console.WriteLine("Game {0}", y + 1);
Console.WriteLine("Enter pass attempts: ");
/*Console.WriteLine("Enter completions: ");    (Just saving from having to enter a ton of data while testing)
Console.WriteLine("Enter completion percentage: ");
Console.WriteLine("Enter total yards: ");
Console.WriteLine("Enter touchdowns: ");
Console.WriteLine("Enter interceptions: ");
Console.WriteLine("Enter rushing yards: ");
Console.WriteLine("Enter rushing touchdowns: ");
Console.WriteLine("Enter fumbles: ");
Console.WriteLine("Enter QB rating: ");
}
}

char letter = 'a';
string input;
{
while (letter != 'z' || letter != 'Z')
{
Console.Write("Enter the first letter of the first name of a player (T, D, P), enter A for all players, or Z to quit: ");
letter = Convert.ToChar(input);
if (letter == 'a' || letter == 'A')
{
Console.WriteLine("Player             Att   Comp  Comp %  PYards PTD INT RYards  RTD  F  QBR");
Console.WriteLine("\n----------------------------------------------------------------------------");
Console.WriteLine("{0}  - Avg  - {1}    {2}     {3}      {4}    {5}   {6}   {7}     {8}   {9}  {10}", players[0], stats[0, 1, 0], stats[0, 1, 1], stats[0, 1, 2].ToString("P"), stats[0, 1, 3], stats[0, 1, 4], stats[0, 1, 5], stats[0, 1, 6], stats[0, 1, 7], stats[0, 1, 8], stats[0, 1, 9].ToString("P"));
Console.WriteLine("\n----------------------------------------------------------------------------");
Console.WriteLine("{0}  - Avg  - {1}    {2}     {3}      {4}    {5}   {6}   {7}     {8}   {9}  {10}", players[1], stats[1, 1, 0], stats[1, 1, 1], stats[1, 1, 2].ToString("P"), stats[1, 1, 3], stats[1, 1, 4], stats[1, 1, 5], stats[1, 1, 6], stats[1, 1, 7], stats[1, 1, 8], stats[1, 1, 9].ToString("P"));
Console.WriteLine("\n----------------------------------------------------------------------------");
Console.WriteLine("{0}- Avg- {1}    {2}     {3}      {4}    {5}   {6}   {7}     {8}   {9}  {10}", players[2], stats[2, 1, 0], stats[2, 1, 1], stats[2, 1, 2].ToString("P"), stats[2, 1, 3], stats[2, 1, 4], stats[2, 1, 5], stats[2, 1, 6], stats[2, 1, 7], stats[2, 1, 8], stats[2, 1, 9].ToString("P"));
}
else if (letter == 't' || letter == 'T')
{
Console.WriteLine("\n----------------------------------------------------------------------------");
Console.WriteLine("Player             Att   Comp  Comp %  PYards PTD INT RYards  RTD  F  QBR");
Console.WriteLine("\n----------------------------------------------------------------------------");
Console.WriteLine("{0}  - Avg  - {1}    {2}     {3}      {4}    {5}   {6}   {7}     {8}   {9}  {10}", players[0], stats[0, 1, 0], stats[0, 1, 1], stats[0, 1, 2].ToString("P"), stats[0, 1, 3], stats[0, 1, 4], stats[0, 1, 5], stats[0, 1, 6], stats[0, 1, 7], stats[0, 1, 8], stats[0, 1, 9].ToString("P"));
}
else if (letter == 'd' || letter == 'D')
{
Console.WriteLine("\n----------------------------------------------------------------------------");
Console.WriteLine("Player             Att   Comp  Comp %  PYards PTD INT RYards  RTD  F  QBR");
Console.WriteLine("\n----------------------------------------------------------------------------");
Console.WriteLine("{0}  - Avg  - {1}    {2}     {3}      {4}    {5}   {6}   {7}     {8}   {9}  {10}", players[1], stats[1, 1, 0], stats[1, 1, 1], stats[1, 1, 2].ToString("P"), stats[1, 1, 3], stats[1, 1, 4], stats[1, 1, 5], stats[1, 1, 6], stats[1, 1, 7], stats[1, 1, 8], stats[1, 1, 9].ToString("P"));
}
else if (letter == 'p' || letter == 'P')
{
Console.WriteLine("\n----------------------------------------------------------------------------");
Console.WriteLine("Player             Att   Comp  Comp %  PYards PTD INT RYards  RTD  F  QBR");
Console.WriteLine("\n----------------------------------------------------------------------------");
Console.WriteLine("{0}- Avg- {1}    {2}     {3}      {4}    {5}   {6}   {7}     {8}   {9}  {10}", players[2], stats[2, 1, 0], stats[2, 1, 1], stats[2, 1, 2].ToString("P"), stats[2, 1, 3], stats[2, 1, 4], stats[2, 1, 5], stats[2, 1, 6], stats[2, 1, 7], stats[2, 1, 8], stats[2, 1, 9].ToString("P"));
}
else
{
Console.WriteLine("Sorry, not a valid initial.");
Console.Write("Enter next players initial or Z to quit ");
letter = Convert.ToChar(input);
}

}
}

}

}
}
``````

## All 5 Replies

Let's say you want Player 1's average of Stat #1 for both games,
This means,
array[0][0][0]
+ array[0][1][0]
/ 2 (games)
= average

This is perfect example how not to make program, learn about OOP, C# is OOP language it will reduce this mess, and make it more maintainable.
In OOP you make Player class with properties like name, score etc ... and methods like calculate average, then you make instance of the player class, pass the array(or Generic List ) to the calculate average method and return and display the result. Easy :)

@Michael27 - So I've been learning programming now for all of 10 weeks in a very part time manner, so forgive me that my program does not look professional. Once I understand the concepts better it will be easier for me to program cleaner.

@Unimportant - I understand that part, my problem is figuring out how to use a method to do that. I have to include a method, loops, array (pre-set and writeable), calculations, and placeholders. I've satisfied all except the calculations and method which is what I'm doing with the average.

I'm a networking guy, just have to learn a small bit of programming so I can complete my bachelors degree.

Still need some help with this if anyone has time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.