Code is to solve a problem w/ company of 4 saleman that sell 5 items and once a day each onputs a dollar value of that product sold for the day.
For some reason the compiler states the index is out of bounds.
public class TotalSales
{
public static void Main(string[] args)
{
const int PEOPLE = 5; // # rows
const int PRODUCTS = 6; // # columns
decimal[,] sales;
sales = new decimal[PEOPLE, PRODUCTS];
decimal value, totalSales;
decimal[] productSales = { 0 };
int salesPerson;
int product;
Console.Write("Enter the salesperson (1-4). enter -1 to end input: ");
salesPerson = Convert.ToInt32(Console.ReadLine());
while (salesPerson != -1)
{
Console.Write("Enter the product number (1-5): ");
product = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter total sales: ");
value = Convert.ToDecimal(Console.ReadLine());
sales[salesPerson, product] += value;
Console.WriteLine(" ");
Console.Write("Enter the salesperson (1-4). enter -1 to end input: ");
salesPerson = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("\n");
Console.WriteLine("The total sales for each salesperson are displayed");
Console.WriteLine("at the end of each row and the total sales for");
Console.WriteLine("each product are displayed at the bottom of each column.");
for (int i = 0; i < 5; i++)
{
totalSales = (decimal)0.0;
Console.Write("{0}", i);
for (int j = 0; j < 6; j++)
{
totalSales += sales[i, j];
Console.Write("sales: {0}", sales[i, j]);
Console.WriteLine("productSales: {0}",productSales[j]);
Console.WriteLine("sales: {0}",sales[i,j]);
[inlinecode]productSales[j] += sales[i,j];[/inlinecode]
}
Console.WriteLine("{0}", totalSales);
} // end for loop
//Console.Write("\nTotal {0}", productSales[1]);
for (int j =1; j < PRODUCTS; j++)
Console.Write("{0}",productSales[j]);
Console.WriteLine("\n");
return;
} // end Main
} // end class