I am writing a program that allows the user to enter sales amounts for 3 sellers and 5 products for each day of the month. I use a 3-dimensional array to store data. I would like to print my data in a tabular format with columns for 3 sellers and rows for five products, each sum of which represents the total sales volume of the product per month, i.e. The sum of 31 values. I also need to have cross totals at the end of each column and row
this is my code:
class Program { static void Main(string[] args) { Slip [,,] sales = new Slip[3, 5, 31]; for (int day = 1; day <= 31; day++) { for (int i = 1; i <= 3; i++) { Console.WriteLine("Enter the salesperson number of #" + i + ":"); int salesPersonNumber = Convert.ToInt16(Console.ReadLine()); Console.WriteLine("Enter the information for day " + day + ", salesperson " + salesPersonNumber + " below:"); for (int j = 1; j <=5; j++) { Console.WriteLine("Enter the product number for product " + j + ":"); int productNumber = Convert.ToInt16(Console.ReadLine()); Console.WriteLine("Enter the total dollar value of the product sold day " + day + ":"); decimal value = Convert.ToDecimal(Console.ReadLine()); Slip slip = new Slip(salesPersonNumber, productNumber, value); sales[i-1, j-1, day-1] = slip; } } } for (int i = 0; i < sales.GetLength(0); i++){ for (int j = 0; j < sales.GetLength(1); j++){ decimal total = 0; for (int k = 0; k < sales.GetLength(2); k++){ total += sales[i, j, k].ValueSold; } Console.WriteLine(total); } } } }
I cannot figure out how to extract data from a three-dimensional array, as described above, to print a table
source share