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]
SuziePosted Feb 18, 2007, 5:54 PM
Scott LyslePosted Feb 18, 2007, 2:48 PM
using System.Collections;
Then create an instance of it:
ArrayList arr = new ArrayList();
Add items to it with the ArrayList add method:
arr.Add(10);
You can iterate through the contents:
for(int i=0; i
Console.Write(arr[i].ToString());
}