0

I have a problem where I'm supposed to input data from different sellers from a salesforce. After the data input I need to sort the sellers into which level of sales they've reached.

The input data are following:

Name: 
SSN:
District: 
Sold articles:

If they've sold 1-49 articles they're level 1, 50-99: level 2, 100-199: level 3 and 199+: level 4.

I'm looking for a way to sort the list in a smart way like:

Level 1: 

Name: Anton
District: Sweden
SSN: 0000000000
Sold articles: 40

Level 2: 

Name: John
District: England
SSN: 1111111111
Sold articles: 89

etc.

in addition to that, my sort function: Array.Sort(salesLevel); doesn't sort the salesLevel for some reason. What am I doing wrong?

This is my code so far:

    public struct Sales
    {
        public string name;
        public string ssn;
        public string district;
        public int articles;
        public int level;

    }
    static void Main(string[] args)
    {
        Sales[] salesperson = new Sales[8];
        for (int i = 1; i <= 6; i++)
        {
            salesperson[i] = new Sales();
            Console.WriteLine("Salesperson {0}", i, +1);
            Console.Write("Name: ");
            salesperson[i].name = Console.ReadLine();
            Console.Write("Social Security Number (SSN): ");
            salesperson[i].ssn = Console.ReadLine();
            Console.Write("District: ");
            salesperson[i].district = Console.ReadLine();
            Console.Write("Number of Sold Articles: ");
            salesperson[i].articles = Convert.ToInt32(Console.ReadLine());
            Console.Write("\n");
            

            if (salesperson[i].articles < 50)
            {
                salesperson[i].level = 1;
            }
            
            else if ((salesperson[i].articles >= 50) && (salesperson[i].articles < 100))
            {
                salesperson[i].level = 2;
            }

            else if ((salesperson[i].articles >=100) && (salesperson[i].articles < 200))
            {
                salesperson[i].level = 3;
            }

            else if (salesperson[i].articles > 199)
            {
                salesperson[i].level = 4;
            }

            else
            {
                Console.WriteLine("Error, invalid amount of articles.");
            }

            

           
            
       

        }
            
            for (int i = 1; i <= 6; i++)
            {

                int[] salesLevel = { salesperson[i].level };
            
                Array.Sort(salesLevel); 

                    for (int j = 0; j < salesLevel.Length; j++)
                    {
                        Console.Write(salesLevel[j]);
                    }

            }

    }

}

}
davidsbro
  • 2,761
  • 4
  • 23
  • 33
Anton
  • 21
  • 4
  • 2
    Diy you notice that `salesLevel` is always a 1-element array? Nothing to sort here. – Klaus Gütter Nov 15 '21 at 18:26
  • [How to sort an array by a specific field](https://stackoverflow.com/questions/1301822/how-to-sort-a-list-of-objects-by-a-specific-field-in-c) – John Wu Nov 15 '21 at 18:29

0 Answers0