0

I am working with Visual Basic and i need to Find the total of each column in the last row Find the grand total in the last cell(the bottom right corner). I know how to do the total thing for this class. But this subject I am working with Arrays. I am sure if that will work with the arrays or will it. I need to have a total at the bottom for this. I am not to sure on how to do it. So if maybe someone might have website i can read on about or something I would be happy. Thanks.

Again this is what I am suppose to do:Find the total of each column in the last row Find the grand total in the last cell(the bottom right corner).

Module Module1
Sub Main()

    Dim sum(5, 4) As Integer
    Dim row, col As Integer
    Dim total As Integer
    For row = 0 To 4
        For col = 0 To 3
            sum(row, col) = row + col
            sum(row, 4) += row + col
        Next col
    Next row
    For row = 0 To 5
        For col = 0 To 4
            Console.Write(sum(row, col) & vbTab)
        Next col
        Console.WriteLine()
    Next row

End Sub

End Module

2
  • 1
    Since you posted a question, it's rather obvious you have a question. Give it a real title. Commented Apr 27, 2011 at 11:40
  • I'm confused on what you're trying to ask; could you elaborate/clarify? Commented Apr 27, 2011 at 11:42

1 Answer 1

1

One big problem is that you're traversing the array by ROWS then columns.

Doing that, you'll sum up each ROW not each COLUMN.

First step would be to reverse that.

Second, you appear to be storing the col totals on row 4, so you can't step down to row 4, just row 3.

Finally, you appear to be adding the value of the row and col vars, instead of the array entry pointed to by those vars.

Something more like this

   For col = 0 to 3
      for row = 0 to 3
         sum(4, 4) += Sum(row, col)
         sum(4, col) += Sum(row, col)
    ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.