Uses a jagged array to store sales figures
/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa
Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
// Sales.cs -- Uses a jagged array to store sales figures, then writes report
// for one month. Demonstrates that you do not have to worry about
// looking for empty elements.
//
// Compile this program with the following command line:
// C:>csc Sales.cs
//
namespace nsSales
{
using System;
public class Sales
{
static public void Main ()
{
DateTime now = DateTime.Now;
Random rand = new Random ((int) now.Millisecond);
int [] MonthLen = new int []
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
double [][] Sales2000 = new double [12][];
for (int x = 0; x < MonthLen.Length; ++x)
{
Sales2000[x] = new double [MonthLen[x]];
for (int y = 0; y < Sales2000[x].Length; ++y)
{
Sales2000[x][y] = rand.NextDouble() * 100;// % 11 + 20;
}
}
Console.Write ("February Sales Report (in thousands):");
for (int x = 0; x < Sales2000[1].Length; ++x)
{
if ((x % 4) == 0)
Console.WriteLine ();
Console.Write (" Feb. {0,-2:D}: {1,-4:F1}", x + 1, Sales2000[1][x]);
}
}
}
}
Related examples in the same category