Sunday, April 27, 2014

Random lottery number generator.


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)
{
//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();

//write the arrays contents to the file
foreach (int value in randomNumbers)



{
outputlistbox1.items.add(value);
}
}
catch (Exception ex)
{
//dislpay an error message.
MessageBox.Show(ex.message);

updated

No comments:

Post a Comment