Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hi my friends:
i want to take 10 numbers from user that show me the smallest and biggest number and i want to do it with array. in windows application. please help me.
thanks
Posted
Comments
Sergey Alexandrovich Kryukov 2-Oct-12 16:10pm    
Help with what? This is not a question; and it's not clear what you want and where did you stuck. What smallest and biggest numbers, for goodness sake?
--SA
fatima...68 2-Oct-12 17:04pm    
smallest and biggest number through inputting numbers
Ravi Bhavnani 2-Oct-12 16:10pm    
This smells like homework. What have you tried doing?
fatima...68 2-Oct-12 17:01pm    
it is a very simple example but i dont know that how i can put numbers from text box in array
JOHN 602 2-Oct-12 16:39pm    
It looks like that if smb don't want do smth by him/herself and first of all go and post it on the site. Maybe there is a simpleton who will scribble the answer.
Your question it is just a nonsense.You may found how to operate with the arrays, I bet, on the first 50 pages of any book related to C#

OK, i'll help you, but algorithm to display the biggest and smallest values, you must to write by yourself.
Steps to do:
1) Create new windows application project
2) On the form place:
- 1x TextBox
- 3x Buttons (change the names as follow: BtnAdd, BtnClear, BtnDisplayResults)
- 1x ListBox
3) copy and paste the code below:
VB
Public Class Form1

    Dim numbers As List(Of Integer) = Nothing 'declare list of integer

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        numbers = New List(Of Integer) 'initialize variable
        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Protected Overrides Sub Finalize()
        numbers = Nothing
        MyBase.Finalize()
    End Sub

    Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
        Dim sText As String = String.Empty
        sText = Me.TextBox1.Text 'get text from TextBox
        numbers.Add(Integer.TryParse(sText, 0)) 'try to add parsed value
        Me.TextBox1.Text = String.Empty 'clear TextBox
        Me.TextBox1.Focus() 
        Me.ListBox1.Items.Add(sText)
    End Sub

    Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
        Me.ListBox1.Items.Clear()
        numbers.Clear()
    End Sub

    Private Sub BtnDisplayResults_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDisplayResults.Click
        'here you need to write custom algorithm

    End Sub

End Class

4) Compile project

I use: ListOf(T)[^] to store numbers.
 
Share this answer
 
Comments
fjdiewornncalwe 3-Oct-12 12:42pm    
My vote of 2. Doing someone's homework will certainly NOT help them learn. By all means given them concepts and such, but giving them copy/paste capable code is useless for them.
Maciej Los 3-Oct-12 16:50pm    
Marcus, have i done OP's homework? Not! Please have a look at the code. The main part of code - algorithm to show/display min and max values - is not implemented. So, OP need to study the code to understand it's meaning.
I can accept your vote, but i can't agree with your comment.
The codes that you need are below (You should write your values inside a textbox inserting spaces between them):
C#
string[] strArray = TextBox1.Text.Split(' ');

int biggest = Int32.MinValue;
int smallest = Int32.MaxValue;

for (int i = 0; i < strArray.Length; i++)
{
    int intVal = Int32.Parse(strArray[i].Trim());

    if (intVal > biggest)
        biggest = intVal;

    if (intVal < smallest)
        smallest = intVal;
}

MessageBox.Show("The biggest: " + biggest.ToString() +
                ", The smallest: " + smallest.ToString());
 
Share this answer
 
Comments
fjdiewornncalwe 3-Oct-12 12:42pm    
My vote of 2. Doing someone's homework will certainly NOT help them learn. By all means given them concepts and such, but giving them copy/paste capable code is useless for them.
Huseyin Atasoy 3-Oct-12 12:51pm    
I am just trying to give the answer. I don't have to think if she will learn, this is her problem! If she want, she can learn many things from an example. We are not her teachers.
There was a question and this is the answer.
Please don't downvote the answers again for your personal obsessions!
fjdiewornncalwe 3-Oct-12 12:55pm    
That is where you are wrong. If we are providing solutions here on CP, we ARE teachers and should take that approach. Most CP members do not condone cut/paste solutions for clear homework questions because we do not want to work with people who will graduate without knowing anything. Don't flatter yourself with the "personal obsession" statement. When I downvote I do it on principle based on community values. It isn't personal.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900