alright here is my issue i dont know how to even start this problem iam still new to vb so i need lil guidance and help in the right direction. here is the problem :

Use a one-dimensional array to solve the following problem: Read in 20 numbers, each of which is between 10 and 100, inclusive. As Each number is read, print it only if it is not a duplicate of a number already read. provide the "worst case" (in which all 20 numbers are different). use the smallest possible array to solve this problem

so any ideas to give me on how to start ?? examples ?? also forgot to mention has to display in listbox well doesnt have to butt thats what was in the orginal directions please help me with this ?? iam such a noob

alright here is my issue i dont know how to even start this problem iam still new to vb so i need lil guidance and help in the right direction. here is the problem :

Use a one-dimensional array to solve the following problem: Read in 20 numbers, each of which is between 10 and 100, inclusive. As Each number is read, print it only if it is not a duplicate of a number already read. provide the "worst case" (in which all 20 numbers are different). use the smallest possible array to solve this problem

The smallest possible array to solve this problem that I could think of currently is an array with 2 elements. With the "worst case" of O(1) to find whether the inputted number is duplicated. So "worst case" for all different number is O(n)

Since this forum is for helping not giving answer away, I would like to know what have you learned so far. Do you know how to use Array in VB.NET?

well ive read about it lil bit and know somethings but not much still newish i mean kinda kno how to do loops lil bit so kinda ify lol

Sorry for late reply because I have something to do in my real-life. Well, I can guild you through step by step how to solve this problem from using the simplest solution to the solution that use the smallest possible array.

Lets break the problem into smaller part and focus on solving it one by one.

  1. You need to write a program that ask user to input 20 numbers.
  2. Each number is between 10 to 100. If inputted number is out of the range, ask user again till you get the correct input.
  3. Check if each number is duplicated, if not, print the number.

First, solving the first problem is easy just loop 20 times and ask user input.

For i As Integer = 0 To 19
            Dim result As Integer = InputBox("")
        Next

Then, you need to solve second problem. I assume that you have learned condition. So I am assuming that you can solve it on your own.

For i As Integer = 0 To 19
            Dim result As Integer

            '' Loop until result is between 10 to 100
            result = InputBox("")
        Next

Now, it is time to solve our ultimate problem to check the new inputted number is duplicated. Question yourself this, Lets say I have ten numbers. I hide the first 9 numbers. Then show you the last number. Then I ask you if the last number will be duplicated with the first 9 numbers. It is impossible to solve this problem because without knowing the first 9 number, you will never know the last number will be duplicated. It is also the same with computer. Computer is the most stupid thing in the world. So computer need to know all the inputted number to decide whether the newly added number is duplicated. Then this is where Array become shining because array allow you to store multiple thing. Since there will be 20 inputted number. Then, you need an array with 20 elements. As each new number inputted, you store it in array.

Dim NumberList(19) As Integer

        For i As Integer = 0 To 19
            Dim result As Integer

            '' Loop until result is between 10 to 100 
            ''(YOU NEED TO SOLVE THIS YOURSELF)
            result = InputBox("")

            '' Storing each inputted number in an array.
            NumberList(i) = result
        Next

Now you have all previous inputted number, then it is very easy to check whether the newly inputted number is duplicated. How? Ask yourself what would you do in real life. If 9 numbers are given, then I give you another number and ask you if my newly given number is duplicated to other 9 numbers. You probably compare each number to the newly given number. If there is any number that match with newly given number, Then it is duplicated.

This is the easiest way to deal with this problem, but it does not use the smallest array as possible. However, I believe that you need to be able to solve the problem.

Edited 5 Years Ago by invisal: n/a

Thanks iam gonna break it down try to use your code lines to solve it althought my friend dug out this old code he had is there anyway to modify it and make it work ?? as in if the form loads displays within a listbox ?? jw tho iam more leaning on ur code and tons of book support lol

Option Explicit

Private Sub removeDuplicates(ByRef arrName() As Long)
    Dim i As Long, tempArr() As Long: ReDim tempArr(UBound(arrName))
    Dim d As New Dictionary, n As Long
    For i = 0 To UBound(arrName)
        If Not d.Exists(arrName(i)) Then
            d.Add arrName(i), arrName(i)
            tempArr(n) = arrName(i): n = n + 1
        End If
    Next
    ReDim Preserve tempArr(n)
    arrName = tempArr
End Sub

Private Sub Form_Load()
    Dim x() As Long, i As Long: ReDim x(99)
    
    '' this loop will fill the array with values :
    '' 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3...
    ''
    For i = 0 To 99
        x(i) = i Mod 4
    Next
    
    '' now remove the duplicated items
    ''
    removeDuplicates x
    
    '' now display whats left
    For i = 0 To UBound(x) - 1
        Debug.Print i & ":" & x(i)
    Next
End Sub

I haven't carefully read your friend code, but from what I scan through your friend code is about filling an array with number from 0 to 3. Then remove duplicated number in the array. If you insist to use your friend code then you can fill user input into an array of 20 elements. Then remove the duplicated element.

However, it seem like it violet the requirement to your problem. As you stated in your first post that you want "As Each number is read, print it only if it is not a duplicate of a number already read".

Moreover, your friend code is not very effective. His code can be more simpler and faster.

Following my earlier post step by step, if you have any question feel free to ask. Forgive me that I cannot give you a full code because it is against the DaniWeb's rule and as well as my own moral. I prefer guiding rather than a homework-generator.

Edited 5 Years Ago by invisal: n/a

This article has been dead for over six months. Start a new discussion instead.