C#任务(按卖家数量排序)

发布于 2025-01-15 04:46:35 字数 2911 浏览 2 评论 0原文

我对编程比较陌生,正在阅读一门入门课程,其中一项任务是阅读销售队伍中性工作者的信息。销售数据必须根据每个卖家达到的销售级别进行排序,最好是级别最高的排在前面。有四个级别,其中第四级最高。

在程序结束时,销售数据必须将排序后的销售数据打印到屏幕和文本文件中。

必须为每个销售人员加载以下信息:

  • 姓名。
  • 社会安全号码。
  • 区。
  • 已售商品数量。

我还没有真正正确排序,我想将不同的工人放在同一类别中(不知道如何处理这里的 Getlevel 函数),如下例所示:

姓名: 社会安全号码: 区: 文章:

Tina 49685958 East 10

约翰 5869494 东 40

埃里克 59704696 悉尼 40 3 卖家已达到 1 级:<50 件商品

Tyler 06486979 South 200

Anna¡ 68396859 West 200

Filip 58496849 Väst 200 3 卖家有相当4级:> 200 项

现在我在每个工人之后得到结果::

姓名: 社会安全号码: 区: 文章:

Eva。 49685958。东。 10 1 个卖家已达到 1 级:<50 件商品

Johan。 5869494东。 40 1 个卖家已达到 1 级:<50 件商品

这是我的代码:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApp2
{
    class Program
    {

        static void Main(string[] args)
        {
            // Deklarerar arrays
            string[] name = new string[6];
            string[] ssn = new string[6];
            string[] district = new string[6];
            int[] qty = new int[6];

            // For loop för att kunna mata in 6 säljare
            for (int i = 0; i <= 5; i++)
            {
                Console.Write("Name: ");
                name[i] = Console.ReadLine();

                Console.Write("Social security number: ");
                ssn[i] = Console.ReadLine();

                Console.Write("District: ");
                district[i] = Console.ReadLine();

                Console.Write("Number of items sold: ");
                qty[i] = int.Parse(Console.ReadLine());

                Console.WriteLine("\n");
            }

            Console.WriteLine("\nName:\t\tSocial security number:\tDistrict:\tNumber of items sold:");

            // Prints salespeople
            for (int i = 0; i < name.Length; i++)
            {
                Array.Sort(qty);
                Array.Reverse(qty);

                Console.WriteLine(name[i] + "\t" + ssn[i] + "\t" + district[i] + "\t" + qty[i]);
                Console.WriteLine("\n");
                GetLevel(qty[i]);
            }


            // To prevent the console from closing
            Console.ReadLine();
        }

        // Function that calculates the level the seller ends up in
        static void GetLevel(int qty)
        {
            if (qty < 50)
                Console.WriteLine(" Seller has reached level 1: <50 items.");

            if (qty >= 50 && qty < 100)
                Console.WriteLine(" Sellers have reached level 2: 50-99 items");

            if (qty >= 100 && qty < 200)
                Console.WriteLine(" Sellers have reached level 3: 100-199 items.");

            if (qty > 200)
                Console.WriteLine(" sellers have reached level 4:> 200 items.");
        }
    }
}

I am relatively new to this with programming and am reading an introductory course where one task is to read information from sex workers in a sales force. The sales data must be sorted depending on the sales level that each seller has reached, preferably with the highest level first. There are four levels where level four is highest.

At the end of the program, the sales data must print the sorted sales data to both the screen and to a text file.

The following information must be loaded for each salesperson:

  • Name.
  • Social security number.
  • District.
  • Number of items sold.

I have not really got the sorting right and I want to put the different workers in the same category (do not know how to handle my Getlevel function here) as the following examples:

Name: Social security number: District: Articles:

Tina 49685958 East 10

Johan 5869494 Öst 40

Eric 59704696 Syd 40
3 Sellers have reached level 1: <50 items

Tyler 06486979 South 200

Anna¨ 68396859 West 200

Filip 58496849 Väst 200
3 Sellers have pretty level 4:> 200 items

Right now I get the result after each worker::

Name: Social security number: District: Articles:

Eva. 49685958. East. 10
1 seller has reached level 1: <50 items

Johan. 5869494 East. 40
1 seller has reached level 1: <50 items

Here is my code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApp2
{
    class Program
    {

        static void Main(string[] args)
        {
            // Deklarerar arrays
            string[] name = new string[6];
            string[] ssn = new string[6];
            string[] district = new string[6];
            int[] qty = new int[6];

            // For loop för att kunna mata in 6 säljare
            for (int i = 0; i <= 5; i++)
            {
                Console.Write("Name: ");
                name[i] = Console.ReadLine();

                Console.Write("Social security number: ");
                ssn[i] = Console.ReadLine();

                Console.Write("District: ");
                district[i] = Console.ReadLine();

                Console.Write("Number of items sold: ");
                qty[i] = int.Parse(Console.ReadLine());

                Console.WriteLine("\n");
            }

            Console.WriteLine("\nName:\t\tSocial security number:\tDistrict:\tNumber of items sold:");

            // Prints salespeople
            for (int i = 0; i < name.Length; i++)
            {
                Array.Sort(qty);
                Array.Reverse(qty);

                Console.WriteLine(name[i] + "\t" + ssn[i] + "\t" + district[i] + "\t" + qty[i]);
                Console.WriteLine("\n");
                GetLevel(qty[i]);
            }


            // To prevent the console from closing
            Console.ReadLine();
        }

        // Function that calculates the level the seller ends up in
        static void GetLevel(int qty)
        {
            if (qty < 50)
                Console.WriteLine(" Seller has reached level 1: <50 items.");

            if (qty >= 50 && qty < 100)
                Console.WriteLine(" Sellers have reached level 2: 50-99 items");

            if (qty >= 100 && qty < 200)
                Console.WriteLine(" Sellers have reached level 3: 100-199 items.");

            if (qty > 200)
                Console.WriteLine(" sellers have reached level 4:> 200 items.");
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷爱 2025-01-22 04:46:36

如果运行此代码,则永远不会调用函数 GetLevel,因此程序不会打印它。删除评论

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApp2
{
    class Program
    {

        static void Main(string[] args)
        {
            // Deklarerar arrays
            string[] name = new string[6];
            string[] ssn = new string[6];
            string[] district = new string[6];
            int[] qty = new int[6];

            // For loop för att kunna mata in 6 säljare
            for (int i = 0; i <= 5; i++)
            {
                Console.Write("Name: ");
                name[i] = Console.ReadLine();

                Console.Write("Social security number: ");
                ssn[i] = Console.ReadLine();

                Console.Write("District: ");
                district[i] = Console.ReadLine();

                Console.Write("Number of items sold: ");
                qty[i] = int.Parse(Console.ReadLine());

                Console.WriteLine("\n");
            }

            Console.WriteLine("\nName:\t\tSocial security number:\tDistrict:\tNumber of items sold:");

            // Prints salespeople
            for (int i = 0; i < name.Length; i++)
            {
                Array.Sort(qty);
                Array.Reverse(qty);

                Console.WriteLine(name[i] + "\t" + ssn[i] + "\t" + district[i] + "\t" + qty[i]);
                Console.WriteLine("\n");
                GetLevel(qty[i]);
            }


            // To prevent the console from closing
            Console.ReadLine();
        }

        // Function that calculates the level the seller ends up in
        static void GetLevel(int qty)
        {
            if (qty < 50)
                Console.WriteLine(" Seller has reached level 1: <50 items.");

            if (qty >= 50 && qty < 100)
                Console.WriteLine(" Sellers have reached level 2: 50-99 items");

            if (qty >= 100 && qty < 200)
                Console.WriteLine(" Sellers have reached level 3: 100-199 items.");

            if (qty > 200)
                Console.WriteLine(" sellers have reached level 4:> 200 items.");
        }
    }
}

If you run this code, the function GetLevel is never called, so the program don't print it. Remove the comment

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApp2
{
    class Program
    {

        static void Main(string[] args)
        {
            // Deklarerar arrays
            string[] name = new string[6];
            string[] ssn = new string[6];
            string[] district = new string[6];
            int[] qty = new int[6];

            // For loop för att kunna mata in 6 säljare
            for (int i = 0; i <= 5; i++)
            {
                Console.Write("Name: ");
                name[i] = Console.ReadLine();

                Console.Write("Social security number: ");
                ssn[i] = Console.ReadLine();

                Console.Write("District: ");
                district[i] = Console.ReadLine();

                Console.Write("Number of items sold: ");
                qty[i] = int.Parse(Console.ReadLine());

                Console.WriteLine("\n");
            }

            Console.WriteLine("\nName:\t\tSocial security number:\tDistrict:\tNumber of items sold:");

            // Prints salespeople
            for (int i = 0; i < name.Length; i++)
            {
                Array.Sort(qty);
                Array.Reverse(qty);

                Console.WriteLine(name[i] + "\t" + ssn[i] + "\t" + district[i] + "\t" + qty[i]);
                Console.WriteLine("\n");
                GetLevel(qty[i]);
            }


            // To prevent the console from closing
            Console.ReadLine();
        }

        // Function that calculates the level the seller ends up in
        static void GetLevel(int qty)
        {
            if (qty < 50)
                Console.WriteLine(" Seller has reached level 1: <50 items.");

            if (qty >= 50 && qty < 100)
                Console.WriteLine(" Sellers have reached level 2: 50-99 items");

            if (qty >= 100 && qty < 200)
                Console.WriteLine(" Sellers have reached level 3: 100-199 items.");

            if (qty > 200)
                Console.WriteLine(" sellers have reached level 4:> 200 items.");
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文