VenomXt
\
- Joined
- 11 Mar 2004
- Messages
- 3,454
Ok here is the problem
This is the code have generated so far
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.
Write an application which will:
[FONT="] [/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="] [/FONT]Check user’s input to prevent the input of any wrong numbers. (i.e.. negative numbers, except -1)
[FONT="] [/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="] [/FONT]Find (or create) and implement any sorting algorithm and use it to sort the first copy of the array.
[FONT="] [/FONT]Use the standard Array.Sort method to sort the second copy of the array.
[FONT="] [/FONT]Output all three arrays in one table (see example).
[FONT="][/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.