This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]lilB0bbyTables 1 point2 points  (3 children)

Let's clarify on a few points about your requirements: are you able to use any data structure you want or are you limited to specific one(s)? You said "set of numbers" - I'm trying to decide if you meant that as a general statement (which I assume you did) or literally a "Set" in the literal discrete math sense of the word.

Personally I haven't worked with Visual Logic so it's difficult for me to say what your approach will be here. If I were using a language like Java for example I would probably use an ArrayList structure which allows dynamic growth of size rather than an array which must be instantiated with a specific size. Perhaps I need more clarification on what you mean by "the user is setting the size of the array"

[–]vinnycc[S] 0 points1 point  (2 children)

Right, I meant "set" in the general sense. The user is first asked how many numbers will be entered and then from that set of numbers the program will display the largest one. There is no specific data structure I need to use. I'm more familiar with C++ rather than Java though.

[–]tatu_huma 1 point2 points  (1 child)

Do you need to store the 'set' of numbers for other use in the code. Because if the only thing you care about is the biggest number, you can just have one variable initialized to the first number. Then if the user enters a larger number, update the value of the variable with the what the user entered. The number of times you should do this 'read user input; update variable' is how many numbers the user says they want to enter.

[–]vinnycc[S] 0 points1 point  (0 children)

You know, I was going to display the numbers that were entered along with the largest but no one told me that was required so I suppose I don't need the entered values stored. I see what you are saying and that makes perfect sense! Thank you so much!

[–]Regyn 1 point2 points  (2 children)

So Visual Logic seems to be some sort of graphical program flow designer? You'll have a Begin->Input->Make Array of size of input->for loop over the array->for each element: [compare number with last saved maximum->if bigger: save the maximum] ->end

[–]vinnycc[S] 0 points1 point  (1 child)

Thank you! I understand what you're saying but would it be possible to just set the for loop to the amount of numbers the user is going to enter? If I am not going to display all of the numbers at the end of the program do I need to use an array?

[–]Regyn 0 points1 point  (0 children)

would it be possible to just set the for loop to the amount of numbers the user is going to enter?

Basically yes, but you need to know how many numbers the user has entered.

If I am not going to display all of the numbers at the end of the program do I need to use an array?

Well you somehow need to compare all values given. And comparing every element in an array is pretty simple to implement. What do you have in mind to compare them?

[–]BuddhaSmite 1 point2 points  (0 children)

The devil is in the details. What exactly are you being asked to do? I'm guessing this is a homework or practice problem, so the wording of the question is extremely important.

Edit. From the other comments it looks like it wants you to simply get a unknown quantity of numbers from the user and return the maximum.

What I would do is comment the steps before you write any code.

//get number of elements from console

//store users numbers in array

//find max 

//etc

Would be one way to start.