# Homework help

• ### Question

• I am working on my homework and am having a duh moment. It's a review question in my VB 2012 book, the question is as follows.

The intNums array is declared as follows: Dim intNums() As Integer = {10, 5, 7, 2}. Which of the following blocks of code correctly  calculates the average value stored in the array? The inTotal, intSub, and dblAvg variables contain the number 0 before the loop is proccessed.

A. Do While intSub < 4

intNums(intSub) = intTotal + intTotal

intSub += 1

Loop

dblAvg = intTotal / intSub

B. Do While intSub < 4

intTotal += intNums(intSub)

intSub = intSub + 1

Loop

dblAvg = intTotal / intSub

C. Do While intSub < 4

intTotal += intNums(intSub)

intSub += 1

Loop

dblAvg = intTotal / intSub  -1

D. Do While intSub < 4

intTotal = intTotal + intNums(intSub)

intSub = intSub + 1

Loop

dblAvg = intTotal / (intSub)

I think the answer is A but I want to be sure because the next 4 questions are based off of this question. Sorry in advance if I am not posting this in the correct forum, I am new to the sight.

• Edited by Tuesday, April 7, 2015 11:49 PM
Tuesday, April 7, 2015 11:33 PM

• If you have to do it without trying inside VB, then take a piece of paper and write down the values of the variables and how they change with every statement being executed. Then you see what happens and if it does what it is supposed to do.

Armin

Tuesday, April 7, 2015 11:39 PM

### All replies

• If you have to do it without trying inside VB, then take a piece of paper and write down the values of the variables and how they change with every statement being executed. Then you see what happens and if it does what it is supposed to do.

Armin

Tuesday, April 7, 2015 11:39 PM
• I don't have any other code for it, it's just a review question.  I hink that the answer is A. but I just wanted a second opinion.
Tuesday, April 7, 2015 11:45 PM
• I was not asking for other code. I've shown you a way how you can confirm it yourself without the confirmation of others. What you would get here is not an opinion but the solution for your homework because it's not a matter of taste what's wrong or right.

Armin

Tuesday, April 7, 2015 11:52 PM
• Thanks for the help. That's pretty much why I don't use these forums (this is my first time ever). I am getting an A in this class and the first time I ask for help I can't get a straight answer. I understand that you want me to figure it out myself but if you didn't want to answer the question why even reply. I probably won't ask again for help...
Wednesday, April 8, 2015 12:06 AM
• Thanks for the help. That's pretty much why I don't use these forums (this is my first time ever). I am getting an A in this class and the first time I ask for help I can't get a straight answer. I understand that you want me to figure it out myself but if you didn't want to answer the question why even reply. I probably won't ask again for help...

Please don't ask for help again if you just want someone to do your homework for you. That's not what we are here for, and it won't help you in the long run.

On the other hand if you need a tip on how you can find the answer for yourself, we can help with that (as Armin did in his reply).

Wednesday, April 8, 2015 12:27 AM
• I feel sorry that you're disappointed now, and I understand it. However, at least in this forum it's common practice to help people help themselves, especially if it's about homework, so it's not a personal issue.

I did and do not know in which learning phase you are. Therefore, my intention was trying to point out a common method to become clear about the right solution yourself.

Armin

Wednesday, April 8, 2015 12:32 AM
• I don't have any other code for it, it's just a review question.  I hink that the answer is A. but I just wanted a second opinion.

As noted you can't get an opinion on an objective question.  There is simply one correct answer.  But if you want an opinion, mine would be that you take another guess at the answer.

Armin gave you the sure-fire way to figure out which one is correct; just work them both and see what the answer is.  But to extrapolate the answer from the question without working it out (probably the goal of this exercise), consider what needs to be done... you must get the average of four numbers.  So what do you need to do to get an average?  You need to get the sum of the numbers and then divide by the count (I'm pretty sure this basic math was not considered part of the question).  If you talk yourself through each of those code snippets, only one of them should sound like it totals the sum and divides by the count.

Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

Wednesday, April 8, 2015 12:40 AM
• I believe most student learn 0% problem solving and just 100% logic. My feeling from this forum are approaches to problem solving a good mental muscle to have - I would not be angry from this but accept and learn how to approach problems - it is problem solving, very necessary for real life job of developing.

EDIT: one explanation: the only people who passed calculus with me were the people who knew problem solving. The people who could only know logic used to get A and highest score and now in this teacher class they got F some got D - they failed very bad mostly because the teacher was testing exam only problem solving skills - very tricky. This is how real life developing is and you better start to exercise the muscle how to problem solve now you will never regret it.

• Edited by Wednesday, April 8, 2015 12:52 AM
Wednesday, April 8, 2015 12:48 AM
• With homework you are not always doing the best solution.

Sometimes is given an assignment to show you in the next section that there is a better solution.

Therefore is asking help in a forum for homework mostly nonproductive.

Success
Cor

Wednesday, April 8, 2015 9:14 AM
• I don't have any other code for it, it's just a review question.  I hink that the answer is A. but I just wanted a second opinion.

If you think the answer is A, then provide a description of how you came to that conclusion.  If there are errors in your thinking someone might point them out so that you can re-evaluate your selection.

You could describe how you decided on A by writing out in plain English what each line of code does.

Wednesday, April 8, 2015 9:47 AM