0
Reply

Figure golf bets using C#

Tim Camper

Tim Camper

Jul 13 2009 12:33 AM
2.4k
Would like to figure golf bets with variable number of players week to week.
Handicaps change every two weeks.
I have the "net score for each hole" algorithm complete for taking the gross score and computing if you get a stroke on that hole or not.
I am asking the program the following:
Player name: // not same players every week
Player handicap: // handicap changes every two weeks
Player gross score for all 18 holes: // hole1: hole2, etc.
I am successful up to this point for capturing info for 1 player and writing to array.
I would like to loop and capture the scores, figure bets, etc,. for all the players.
I keep leaning toward using arrays but get errors about using variable again.
I program as hobby and do not make my living doing programs.
Any tips or suggestion would be appreciated.
Here what have so far.

// Name: FigureNetHandicap
// Author - Tim Camper

using System;
using System.Collections;

public class net
{
    public static void Main()
    {
      
        //double hole1net, hole2net, hole3net, hole4net, hole5net, hole6net, hole7net, hole8net, hole9net = 0;
        //double hole10net, hole11net, hole12net, hole13net, hole14net, hole15net, hole16net, hole17net, hole18net = 0;
        double hole1net = 0;
        double hole2net = 0;
        double hole3net = 0;
        //double hole4net = 0;
        //double hole5net = 0;
        //double hole6net = 0;
        //double hole7net = 0;
        //double hole8net = 0;
        //double hole9net = 0;
        //double hole10net = 0;
        //double hole11net = 0;
        //double hole12net = 0;
        //double hole13net = 0;
        //double hole14net = 0;
        //double hole15net = 0;
        //double hole16net = 0;
        //double hole17net = 0;
        //double hole18net = 0;


        int hole1hcp = 10;  // static, does not change
        int hole2hcp = 18;
        int hole3hcp = 8;
        //int hole4hcp = 4;
        //int hole5hcp = 12;
        //int hole6hcp = 14;
        //int hole7hcp = 16;
        //int hole8hcp = 2;
        //int hole9hcp = 6;
        //int hole10hcp = 15;  // static, does not change
        //int hole11hcp = 17;
        //int hole12hcp = 1;
        //int hole13hcp = 9;
        //int hole14hcp = 13;
        //int hole15hcp = 11;
        //int hole16hcp = 7;
        //int hole17hcp = 3;
        //int hole18hcp = 5;


        Console.WriteLine("\n");
        Console.Out.Write("Player1 Name: ");
        string playernameString = System.Console.ReadLine();
        String NamePlayer1 = System.Convert.ToString(playernameString);
        Console.WriteLine("\n");

        Console.Out.Write("Enter " + NamePlayer1 + "'s Handicap: ");
        string handi1String = System.Console.ReadLine();
        double Player1Handicap = System.Convert.ToDouble(handi1String);
        Console.WriteLine("\n");


        ArrayList Player1Gross = new ArrayList();    // Array for Gross Score for Player1
        ArrayList Player1Net = new ArrayList(); // Array for Net Score for Player1

        Console.WriteLine();

        Console.Out.Write("Hole 1 Gross: ");  // Player1 enters gross score for hole # 1
        string num1String = System.Console.ReadLine();
        double hole1gross = System.Convert.ToDouble(num1String);  // hole1gross is gross score for hole # 1
        if (hole1hcp >= Player1Handicap)  // (if loop) figures Player1 net for hole # 1                
            hole1net = hole1gross;  // hole1net and hole1gross gets added to array after entering all gross scores for Player1.
        else hole1net = hole1gross - 1;
               
        Console.Out.Write("Hole 2 Gross: ");
        string num2String = System.Console.ReadLine();
        double hole2gross = System.Convert.ToDouble(num2String);
        if (hole2hcp >= Player1Handicap)
            hole2net = hole2gross;
        else hole2net = hole2gross - 1;

        Console.Out.Write("Hole 3 Gross: ");
        string num3String = System.Console.ReadLine();
        double hole3gross = System.Convert.ToDouble(num3String);
        if (hole3hcp >= Player1Handicap)
            hole3net = hole3gross;
        else hole3net = hole3gross - 1;

        //Console.WriteLine("Adding 18 elements");
        // Add elements to the array list
        Player1Gross.Add(hole1gross);
        Player1Gross.Add(hole2gross);
        Player1Gross.Add(hole3gross);
       
        Player1Net.Add(hole1net);
        Player1Net.Add(hole2net);
        Player1Net.Add(hole3net);

        Console.WriteLine("\n");
        Console.WriteLine("\n");
        Console.WriteLine("Hole  01 02 03 04 05 06 07 08 09 Out     10 11 12 13 14 15 16 18 18 In   Total");
        Console.WriteLine("\n");
        Console.WriteLine(" Hcp  10 18 08 04 12 14 16 02 06         15 17 01 09 13 11 07 03 05");
        Console.WriteLine("\n");
        Console.WriteLine(" Par   4  3  4  5  4  3  4  5  4  36      4  3  5  4  3  4  5  4  4  36  72");
        Console.WriteLine("\n");
        Console.WriteLine(NamePlayer1 + "'s");


        // loop to display the gross score using array indexing
        Console.Write("Gross: ");
        for (int i = 0; i < Player1Gross.Count; i++) // indexes
            Console.Write(Player1Gross[i] + " ");
        Console.WriteLine("\n");

        Console.Write("       /  /  /  /  /  /  /  /  /          /  /  /  /  /  /  /  /  /");
        Console.WriteLine("\n");

        // loop to display the net score
        Console.Write("  Net: ");
        for (int i = 0; i < Player1Net.Count; i++)
            Console.Write(Player1Net[i] + " ");
        Console.WriteLine("\n");

    }
}

// path=C:\WINDOWS\Microsoft.NET\Framework\v3.5
// I put the path in my windows environment, should not have to manualy do.
// ;C:\WINDOWS\Microsoft.NET\Framework\v3.5
// cd c:\A-Temp\csharp
// csc FigureNetHandicap.cs