Suzie

Suzie

  • NA
  • 4
  • 0

Help with variable-length arrays

Feb 18 2007 10:18 AM
Hi everyone,
I am new to C# and programming. I have been working on this project for about a week. I need to find out how to create a variable-length array based on user input. For each input, the commission is calculated.  This number is then stored in the array based on a salary range (200-299 - all the way up to 1000 and above). When user enters -1 the program ends and prints out.Please tell me what I am doing wrong?

[code]

static void Main(string[] args)

{

int sales;

do

{

Console.Write("Enter in the sales for the salesperson (-1 to quit): ");

sales = int.Parse(Console.ReadLine());

} while (sales != -1);

{

int[] salesArray = new int[sales];

for (int counter = 0; counter < sales; counter++)

sales = 200 + ((9 / 10) * sales);

//store sales in each salary range

int[] frequency = new int[9];

 

//for each sales frequency increment appropriate counter

foreach (int sales in salesArray)

++frequency[sales / 100];

//for each sales, print number

for (int count = 0; count < frequency.Length; count++)

{

if (count == 100)

Console.Write("1000 and over: ");

else

Console.Write("{0:D2}{1:D2}: ", count * 100, count * 100 + 9);

}

Console.WriteLine("{0,20}{1,30}", "Salary Range", "Number of Salespeople");

}

}

}

}


[/code]

Answers (2)