# Compare 2 int arrays.

Page 1 of 1

## 2 Replies - 1257 Views - Last Post: 23 July 2009 - 08:19 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=116325&amp;s=c027533ed1ceab5734575edb1079c82a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 timcamper

Reputation: 0
• Posts: 20
• Joined: 22-July 09

# Compare 2 int arrays.

Posted 22 July 2009 - 08:59 PM

Part I:
Would like to compare int value T1 index[0...3] to int value D1 index[0...3].
There are 3 possibilities I am interested in writing to screen or capturing.

1. Is the value of T1[0] equal to D1[0] // if not then.
2. Is the value of T1[0] < D1[0] // if not I know D1[0] is larger.
3. Steps 1 & 2 fail, I know D1[0] is larger.

Once prototype done the arrays will actually have 18 values (golf scores). Each array (golf score will get compared to all others.
Example: If 10 Players, Player 1's score gets compared to the other 9.
Player 2 gets compared to P3-P10, Player 3 gets compared to P4-P10. Based on the number of players the compare equation is

[Player(n) = NumberofPlayer - n]

Of course I want the program to compare results and show a 1 on 1 player comparison showing the 1up, even, status of each hole.

Since there are different players week to week and handicaps do change from time to time, I would like to enter name and handicap and corresponding score on each use. However I could live with static for now and just 999 when player not there.

I have made good progress and have a good working method for figuring the net score using the handicap system. I am a hobbyist with a strong technical background. Just looking for a jump start.

Any help on structuring a compare or equals statement would be appreciated.

```// File Name: MethodCompareNetGolfScore
// Author - Tim Camper

using System;

public class Compare
{
public static void Main()
{
int[] T1 = new int[3] { 1, 2, 3 };
int[] D1 = new int[3] { 4, 5, 6 };
Console.Out.WriteLine("");
for (int i = 0; i < T1.Length; i++)
Console.WriteLine("   Hole " + (i+1) + ": " + T1[i]);

```

Is This A Good Question/Topic? 0

## Replies To: Compare 2 int arrays.

• D.I.C Regular

Reputation: 118
• Posts: 388
• Joined: 14-June 09

## Re: Compare 2 int arrays.

Posted 23 July 2009 - 02:48 AM

Sounds like a nice little project.Try something in this order:
```		for (int i = 0; i < (T1.Length); i++)
{
if (T1[i] == D1[i])
Console.WriteLine("Hole {0}: both are equal", i);
else if (T1[i] < D1[i])
Console.WriteLine("Hole {0}: T1 is better than T2", i);
else
Console.WriteLine("Hole {0}: T1 is worse than D1", i);
}
```

This code can go up to 18 holes with no alteration. Also I've shown you here an alternative way of formatting your writes to the console. Pick whichever you like the best. This should get you going. And to add names and total handicaps you could use one of the collection classes, or make your own class.

This post has been edited by Renagado: 23 July 2009 - 02:51 AM

### #3 timcamper

Reputation: 0
• Posts: 20
• Joined: 22-July 09

## Re: Compare 2 int arrays.

Posted 23 July 2009 - 08:19 PM

Renagado, on 23 Jul, 2009 - 01:48 AM, said:

Sounds like a nice little project.Try something in this order:
```		for (int i = 0; i < (T1.Length); i++)
{
if (T1[i] == D1[i])
Console.WriteLine("Hole {0}: both are equal", i);
else if (T1[i] < D1[i])
Console.WriteLine("Hole {0}: T1 is better than T2", i);
else
Console.WriteLine("Hole {0}: T1 is worse than D1", i);
}
```

This code can go up to 18 holes with no alteration. Also I've shown you here an alternative way of formatting your writes to the console. Pick whichever you like the best. This should get you going. And to add names and total handicaps you could use one of the collection classes, or make your own class.