Vb.Net arrays beed help with issue.

  • Thread starter VenomXt
  • https://www.osnn.net/admin.php?templates/thread_view.1970/delete&_xfRedirect=https%3A%2F%2Fwww.osnn.net%2Fadmin.php%3Ftemplates%2Foutdated Start date
Joined
11 Mar 2004
Messages
3,454
Ok here is the problem

Write an application which will:
[FONT=&quot] [/FONT]Allow the user to create an array of up to 100 positive numbers with the use of -1 to stop entering if user needs an array containing less than 100 elements.
[FONT=&quot] [/FONT]Check user’s input to prevent the input of any wrong numbers. (i.e.. negative numbers, except -1)
[FONT=&quot] [/FONT]Make two copies of the array. (Make sure you create two new arrays only of necessary size: exactly as many as it was entered by user. You may need a counter)
[FONT=&quot] [/FONT]Find (or create) and implement any sorting algorithm and use it to sort the first copy of the array.
[FONT=&quot] [/FONT]Use the standard Array.Sort method to sort the second copy of the array.
[FONT=&quot] [/FONT]Output all three arrays in one table (see example).
[FONT=&quot][/FONT]

This is the code have generated so far

Code:
Module numbers

   Sub Main()

      Dim numbers(5) As Integer
      Dim secondnumbers(5) As Integer
      Dim x As Integer
      Dim z As Integer = 0

      For i As Integer = 0 To 5

         Console.WriteLine("Please Enter The Value(-1 to stop)")



         x = Console.ReadLine()

         If x < -1 Then

            Do Until x > -2


               Console.WriteLine("You have entered a negative number, Please Try again")

               x = Console.ReadLine

            Loop
         ElseIf x = -1 Then

            Console.WriteLine("You have opted to quit entering numbers")
            'This rebuilds the array due to wanting to end the number entering early and it preserves the old data.


            i = 5
            z = i

            ' this isnt culling the zeros that are left becase you wanted to end input early
            ReDim Preserve numbers(z)

         End If

         'this is whats getin the data from the read line and entering it into the array

         numbers(i) = x





      Next i

      'If z = 0 Then

      Dim txt As String = ""
      For i As Integer = 0 To 5
         txt &= numbers(i).ToString & vbCrLf

      Next i


      ' The SharedCopy method does exactly what you think it will do, copy an array or pieces of an array to another array. Remember though, you may me copying reference types so approach it accordingly
      Array.Copy(numbers, secondnumbers, z)




      'ouputs
      Console.WriteLine(txt)




      'not sure if i will need

      'Else
      ' Dim txt As String = ""
      'For i As Integer = 0 To 5
      'txt &= numbers(i).ToString & vbCrLf

      'Next i

      'Console.WriteLine(txt)

      ' End If





   End Sub

End Module

I cant get the redim preserve statment to make the array just the input without the remainder array size to be filled with zeros and then a -1. Any ideas? Im stuck.
 

Members online

No members online now.

Latest forum posts

Latest profile posts

Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?

Forum statistics

Threads
62,000
Messages
673,429
Members
5,596
Latest member
Joshua Liansky