Sorting a list of footballers

C-noob

New member
Joined
Oct 10, 2022
Messages
2
Programming Experience
Beginner
So I have a form. I want it to be an input form. So that a footballer can write how many goals he did in one season and then get sorted in a list after.

So the output should look something like this after a few footballers(four of them) have written their stats for the season:

Name Persnr District Number of goals

Footballer-Ian 4503038990 Greenic 17

1 footballer has reached level 3: 10-20 goals



Name Persnr District Number of goals

Footballer-Jan 3505038990 Wardengreen 27

1 footballer has reached level 3: 20-30 goals


And the two other footballers etc....


It does not look like this now. It looks like the attached file output below. I like how the form looks but I want it to output the right stuff also. And it should appear in that black box that normally happens when you run C-sharp I guess.

The existing code looks like this:

C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Bubble_sort_Form
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

       
            //Kallar på funktionen.
            run();


        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        //Write all the functions in here----start

        //funktions deklaration
        void bubbleSort(ref int[] arr)
        {
            int n = arr.Length;
            for (int i = 0; i < n - 1; i++)
                for (int j = 0; j < n - i - 1; j++)
                    if (arr[j] > arr[j + 1])
                    {
                        // swap temp and arr[i]
                        int temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
        }

        /* Prints the array */
        void printArray(int[] arr)
        {
            int n = arr.Length;
            for (int i = 0; i < n; ++i)
            {
                label1.Text = label1.Text + arr[i] + Environment.NewLine;
            }

        }

        // Driver method

   
    void run()
        {
            int[] arr = { 0 - 50, 50 - 99, 100 - 199 };
            bubbleSort(ref arr);
            printArray(arr);
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        //Write all the functions in here?----end

    }

}
 

Attachments

  • Skärmavbild 2022-10-11 kl. 10.04.04.png
    Skärmavbild 2022-10-11 kl. 10.04.04.png
    21.1 KB · Views: 7
Last edited:
You need to debug your code. If you don't know how to debug, stop what you're doing and learn now, then apply what you've learned to this code. You need to set a breakpoint at an appropriate place and then step through the code by line, examining the state at each step. You should know exactly what you expect to happen at each step and you can see exactly what does happen, so you can compare expectation to reality. As soon as the two don't match, you've found an issue. If you can't work out how to solve that issue yourself, at least you can provide us with all the what, where and how.
 
As a starting point though, this is obviously wrong:
C#:
int[] arr = { 0 - 50, 50 - 99, 100 - 199 };
You haven't actually explained what that's supposed to do, which is part of the problem with such broad questions like this, of the form "I want to achieve result X, here's all my code, you figure it out". It appears that you are trying to create ranges of some sort but that's not happening. You're creating an int array so the array will just contain whole numbers, not ranges. Each of those expressions is just a subtraction, so that code is the same as this:
C#:
int[] arr = { -50, -49, -99 };
That's all you're doing. Whatever you're trying to do, I doubt it's that.
 
As a starting point though, this is obviously wrong:
C#:
int[] arr = { 0 - 50, 50 - 99, 100 - 199 };
You haven't actually explained what that's supposed to do, which is part of the problem with such broad questions like this, of the form "I want to achieve result X, here's all my code, you figure it out". It appears that you are trying to create ranges of some sort but that's not happening. You're creating an int array so the array will just contain whole numbers, not ranges. Each of those expressions is just a subtraction, so that code is the same as this:
C#:
int[] arr = { -50, -49, -99 };
That's all you're doing. Whatever you're trying to do, I doubt it's that.
This stuff is supposed to be in the ranges of 10-20 goals, 20-30 goals, 30-40 goals. I had just forgot to change it. Yes it is wrong. I want it to output ranges of footballers but don't know how.

Why is it important to debug the code and where can I learn it?

What does "debugging" actually mean?

When a footballer writes in for example ten goals he should end up in the level of 10-20 goals. Four footballers should be able to input their values. And then the program should run in that black C#-box window and output a sorted list of where they end up in the different levels. Lowest at the top. Highest at the bottom.
 
Last edited:
And it should appear in that black box that normally happens when you run C-sharp
The console window is only normal if you are running a console application. You are writing a WinForms application. it doesn't have a console window associated with it by default.
 
Back
Top Bottom