2 Replies - 1257 Views - Last Post: 23 July 2009 - 08:19 PM Rate Topic: -----

#1 timcamper   User is offline

  • New D.I.C Head

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

Compare 2 int arrays.

Post icon  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.

#2 Renagado   User is offline

  • D.I.C Regular
  • member icon

Reputation: 118
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#3 timcamper   User is offline

  • New D.I.C Head

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

Re: Compare 2 int arrays.

Posted 23 July 2009 - 08:19 PM

View PostRenagado, 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.


Renagado,
Thanks for your help. I had a statics professor years ago that used to say " once you see the answer it is intuitive." Same thing here. Now that I see your suggestions I am wondering why I didn't get there on my own. Again thanks.

I like both formats for write and tend to go back & forth.
Oh yes, I will research the collection class and make some headway.

Tim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1