C# function for sort

This is a discussion on C# function for sort within the C# Programming forums, part of the General Programming Boards category; i need a program than can be ask user : name , age , id , and salary then shows ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    3

    C# function for sort

    i need a program than can be ask user : name , age , id , and salary
    then shows me the maximum salary and minimum salary

    and then sort salary from maximum to minimum .

    please complete these program for me
    Code:
            public string name;a
            public int age;
            public bool ID;
            private int salary;
            public void Staff()
            {
                Console.WriteLine("enter your name");
                name = Console.ReadLine();
                Console.WriteLine("enter your age : ");
                age = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("enter your ID:");
                ID = Console.ReadLine();
                Console.WriteLine("enter your salary:");
                income = Convert.ToInt32(Console.ReadLine());
    
            }

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    3
    i have write some codes but it dose not work yet
    please complete it for me

    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace ConsoleApplication58
    {
        struct Salary
        {
    
             string name;
             int age;
            int ID;
             int salary;
             void Staff()
            {
                Console.WriteLine("enter your name");
                name = Console.ReadLine();
                Console.WriteLine("enter your age : ");
                age = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("enter your ID:");
                ID = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("enter your salary:");
                salary = Convert.ToInt32(Console.ReadLine());
            }
    
            
            
    
                List<Human> Humans = new List<Human>();
            }
    
            void Add(Int16 humanID, string humanName, Int16 humanAge, float humanSalary)
            {
                Humans.Add(new Human(humanID, humanName, humanAge, humanSalary));
            }
    
            float GetMaxSalary()
            {
                float maxSalary = 0;
                foreach (Human aHuman in Humans.ToArray())
                {
                    if (aHuman.SALARY > maxSalary)
                        maxSalary = aHuman.SALARY;
                }
                return maxSalary;
            }
    
            float GetMinSalary()
            {
                float minSalary = GetMaxSalary();
                foreach (Human aHuman in Humans.ToArray())
                {
                    if (aHuman.SALARY < minSalary)
                        minSalary = aHuman.SALARY;
                }
                return minSalary;
            }
    
            float GetAverage()
            {
                float totalSalary = 0;
                foreach (Human aHuman in Humans.ToArray())
                {
                    totalSalary += aHuman.SALARY;
                }
    
                return totalSalary / Humans.Count;
            }
        }
    
        struct Human
        {
            public Int16 ID;
            public string NAME;
            public Int16 AGE;
            public float SALARY;
    
            public Human(Int16 humanID, string humanName, Int16 humanAge, float humanSalary)
            {
                ID = humanID;
                NAME = humanName;
                AGE = humanAge;
                SALARY = humanSalary;
            }
        }
    }

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    You don't need to convert that List to an array in the foreach statements, it's more efficient with what you're doing to leave them as they are using the GetEnumerator method.
    Here to Deceive, Inveigle, Obfuscate Since 1945

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    3
    sorry for my
    but i really can't complete it . thanks alot if you complete it for me

    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace ConsoleApplication54
    {
    
        struct salary
        {
            string name;
            int age;
            int ID;
            int salary;
        }
        class program
        {
    
            public void human()
            {
                Console.WriteLine("enter your name");
                name = Console.ReadLine();
                Console.WriteLine("enter your age : ");
                age = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("enter your ID:");
                ID = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("enter your salary:");
                salary = Convert.ToInt32(Console.ReadLine());
            }
    
            List<Human> Humans = new List<Human>();
    
            void Add(Int16 humanID, string humanName, Int16 humanAge, float humanSalary)
            {
                Humans.Add(new Human(humanID, humanName, humanAge, humanSalary));
            }
    
            float GetMaxSalary()
            {
                float maxSalary = 0;
                foreach (Human aHuman in Humans.ToArray())
                {
                    if (aHuman.SALARY > maxSalary)
                        maxSalary = aHuman.SALARY;
                }
                return maxSalary;
            }
    
            float GetMinSalary()
            {
                float minSalary = GetMaxSalary();
                foreach (Human aHuman in Humans.ToArray())
                {
                    if (aHuman.SALARY < minSalary)
                        minSalary = aHuman.SALARY;
                }
                return minSalary;
            }
    
            float GetAverage()
            {
                float totalSalary = 0;
                foreach (Human aHuman in Humans.ToArray())
                {
                    totalSalary += aHuman.SALARY;
                }
    
                return totalSalary / Humans.Count;
            }
        }
    
        struct Human
        {
            public Int16 ID;
            public string NAME;
            public Int16 AGE;
            public float SALARY;
    
            public Human(Int16 humanID, string humanName, Int16 humanAge, float humanSalary)
            {
                ID = humanID;
                NAME = humanName;
                AGE = humanAge;
                SALARY = humanSalary;
            }
        }
    }

  6. #6
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    IF you can't solve this problem on your own, I don't know what to tell you. I'm not going to complete it for you, no matter how many times you post the source code. You could try MSDN documentation to see if the list class has any methods that can help you.
    Here to Deceive, Inveigle, Obfuscate Since 1945

  7. #7
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,641
    So you've exhausted your sources of people to write your code here, here, and here, so you thought you'd try this place?

    Pathetic.

  8. #8
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I like this quote
    If its not your homework, and you need it *critically* it can only therefore be your job, and if you're being paid to do it, call a collegue..
    ...so he can inform the boss about such a problem.

    It's probably homework, way too simple to solve.
    Here to Deceive, Inveigle, Obfuscate Since 1945

  9. #9
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    The problem is the educational system in Iran that leads to these kind of problems. I've seen many students that are studying IT and computer but can not write even a line of code. They really don't have talent I think. I don't know if its true for other countries or not.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21