Sunday, April 27, 2014

Random lottery number generator.

updated

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{


public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
//create array for numbers
const int NUMBER = 5;
int[] randomNumbers = new int[NUMBER];

//counter variable to use in the loop
int index = 0;

//declare a streamreader variable.
StreamReader inputFile;

//open the file and get a streamreader object.
while (index < randomNumbers.Length && !inputFile.EndOfStream)
{
randomNumbers[index] = int.Parse(inputFile.ReadLine());
index++;
}

//close the file.
inputFile.Close();

//create random object
Random rand = new Random();

foreach (int value in randomNumbers)
{
listBox1.Items.Add(value);
}

}
catch (Exception ex)
{
//dislpay an error message.
MessageBox.Show(ex.Message);


No comments:

Post a Comment