Tuesday, November 9, 2010

More array stuff

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;

namespace ArrayExamples
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.CreateArray();
Console.ReadKey();
}

void CreateArray()
{
int[] myArray = { 1, 3, 5, 20, 51, 3, 2 };
Console.WriteLine(myArray[3].ToString());

//double[,,] myArrayTwo = new double[5,2,1];
//myArrayTwo[0,0, 0] = 2.3;
//myArrayTwo[0,0 ,1] = 2;
//myArrayTwo[0,1, 0] = 4;
//myArrayTwo[0,1, 1] = 4.5;

//string[,] books = new string[3, 2];
//books[0, 0] = "Lord of the Rings";
//books[0, 1] = "Tolkein";
Console.WriteLine("How many scores do you want to enter?");
int number = int.Parse(Console.ReadLine());
int[] scores =new int[number];
FillArray(scores);


}

void FillArray(int[] myScores)
{
for (int i = 0; i < myScores.Length; i++)
{
Console.WriteLine("enter a score");
myScores[i]=int.Parse(Console.ReadLine());
}
DisplayArray(myScores);
}

void DisplayArray(int[] allScores)
{
int sum = 0;
int counter = 0;
foreach (int i in allScores)
{
counter++;
Console.WriteLine("the score for hole {0} is {1}",counter,i.ToString());
sum += i; //sum = sum + i
}

double average = (double)sum / allScores.Length;

Console.WriteLine("The sum of the scores is {0}", sum);
Console.WriteLine("the average of the scores is {0}", average);
Array.Sort(allScores);
Console.WriteLine("the highest score is {0}", allScores.Max());
Console.WriteLine("The Second highest score is {0}", allScores[allScores.Length-2]);
}

void ArraylistExample()
{
ArrayList myList = new ArrayList();
myList.Add("Don't Panic");

List<string> genericArray = new List<string>();

}
}
}

No comments:

Post a Comment