CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 18

Threaded View

  1. #1
    Join Date
    Feb 2007
    Posts
    21

    Help with arrays in C#

    I am new to C# programming and have been working on this project for a week. Here's the logic:

    1. Output total number of salary ranges:
    200 - 299, 300-399, 400-499, 500-599, 600-699, 700-799, 800-899,
    1000+
    2. Input gross sales.
    3. If quit (-1) go to step 8
    4. Calculate the salary =$200 + 9% * gross sales (entered by user)
    5. Determine the salary range that the calculated salary falls into.
    6. Increment a counter for the salary range that was determined.
    7. Repeat steps 2 thru 6.
    8. Display the number of salaries falling into the salary ranges as indicated.
    9. End.

    Any help would be greatly appreciated.

    Code:
     static void Main(string[] args)
          {
    
             int grossSales = 0;
    
             while (grossSales != -1)
             {
                Console.Write("Enter in the sales for the salesperson (-1 to quit): ");
                grossSales = Int32.Parse(Console.ReadLine());
    
                //store grossSales in each salary range array
                int[] frequency = new int[9];
    
                //calculate the salary for each item stored in salary range array
                for (int counter = 0; counter < frequency; counter++)
                frequency[counter] = 200 + ((9/10)* grossSales);
             
                int[] getSalary = new int[];// array of salary of the salespeople
    
                //for each salary, increment the appropriate frequency
                foreach (int salary in getSalary)
                ++frequency[salary / 10];
    
                Console.WriteLine("{0,20}{1,30}", "Salary Range", "Number of Salespeople");
    
                //for each salary, print number
                for (int salary = 0; salary < frequency.Length; salary++)
                {
                if (salary == 10)
                   Console.Write("1000 and over: ");
                else
                   Console.Write("{0:D2}{1:D2}: ", salary * 10, salary * 10 + 9);
    
             }
           
             }
          }
       }
    }
    Last edited by apricotsun; February 16th, 2007 at 03:50 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured