• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Comparing the sums of rows and columns in a 2D array

 
Greenhorn
Posts: 15
Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the code I have for summing the totals of my columns and my rows.



I'm trying to figure out how to say if row one does not equal row two. I'm just not getting the syntax here.

If anyone could help I'd appreciate it.

Thanks
 
author
Posts: 23931
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lonnie Wood wrote:
I'm trying to figure out how to say if row one does not equal row two. I'm just not getting the syntax here.



Well, you are not saving the row totals (or the column totals) anywhere. You calculate a row total, print it, and then calculate the next row using the same variables.

You can't compare one row total to another because your program never have two row totals (at the same time) to allow for any comparison -- much less, for a specific comparison.

Henry
 
Lonnie Wood
Greenhorn
Posts: 15
Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry,

I had tried about twenty different comparison strings but nothing worked.

I'm calculating the totals, but how do I store the value is a better question I guess. How can I say that columnTotal for column0 = columnTotal0 and columnTotal for column1 = columnTotal1?

Hence the reference to a syntax problem.

Thanks
 
Henry Wong
author
Posts: 23931
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lonnie Wood wrote:
I had tried about twenty different comparison strings but nothing worked.

I'm calculating the totals, but how do I store the value is a better question I guess. How can I say that columnTotal for column0 = columnTotal0 and columnTotal for column1 = columnTotal1?




Have you tried creating an array for the column totals? Then you can say "columnTotals[col]" as the total for a particular column.

Henry
 
Lonnie Wood
Greenhorn
Posts: 15
Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry,

No I haven't but that makes sense. Let me try that out and let you know.

Thanks
 
Marshal
Posts: 77158
370
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I take it you have a "rectangular" array, ie all the rows are the same length. Otherwise, if a row is longer than the first row, you will omit its last element and get a wrong answer. If a row is shorter, you will get the far less serious result of an Exception.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic