CSS Style center

CSS Styles, CSS tips

Portfolio

C Sharp console lottery application

Howdy guys,

A friend of mine had to write a small project in C-# (C-Sharp) and i have decided to join him in writing the lottery console application, so that maybe i will learn something from that too…

TheĀ purposeĀ of this application is

  1. get lottery numbers from the user manually or automatically
  2. present them on screen
  3. add another row for winning numbers
  4. show how many hits he had and in witch rows

In this application we used two dimensional arrays for creating a table of numbers and we have added one more row for the winning numbers.

Below is the full code, you may use it for your own purposes if you need.

using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“Welcome to the You can’t win Lottery”);
Console.WriteLine(“************************************”);
Console.WriteLine(“”);
Console.WriteLine(“Please Choose an option”);
Console.WriteLine(“”);
Start:
int pgia = 0;
Console.WriteLine(“1.Automatic Lottery \t 2. Manual Lottery \t 3. Exit”);
int option = int.Parse(Console.ReadLine());
if (option == 3)
{
Console.WriteLine(“Goodbye and have a nice day”);
}
else if (option == 2)
{
Console.WriteLine(“Please choose number of Rows to fill in”);
int turNum = int.Parse(Console.ReadLine());
Console.WriteLine(“Are you sure?(y/n)”);
string sure = Console.ReadLine();
Random rnd = new Random();
int Zmani = new int();
if (sure == “y” || sure == “yes”)
{
int[,] numbers = new int[turNum+1, 6];
for (int CurrentTur = 0; CurrentTur < turNum; CurrentTur++)
{
for (int Misparim = 0; Misparim < numbers.GetLength(1); Misparim++)
{
odpaam:
Console.WriteLine(“Please Enter the number {0} of tur {1}”, Misparim + 1, CurrentTur + 1);
int misparMazal = int.Parse(Console.ReadLine());
if (misparMazal <= 45 && misparMazal > 0)
{
for (int CheckRow = 0; CheckRow < numbers.GetLength(1); CheckRow++)
{
if (numbers[CurrentTur, CheckRow] == misparMazal)
{
Console.WriteLine(“You have already entered this number in this Row, please choose another one”);
goto odpaam;
}
}
numbers[CurrentTur, Misparim] = misparMazal;
}
else
{
Console.WriteLine(“The number you have entered is out of range, please enter numbers 1-45 only”);
goto odpaam;
}
}
}
for (int TurNow = 0; TurNow < turNum; TurNow++)
{
for (int Mispari = 0; Mispari < numbers.GetLength(1); Mispari++)
{
Console.Write(“{0},”, numbers[TurNow, Mispari]);
}
Console.WriteLine();
}
for (int Turnohehi = turNum; Turnohehi < numbers.GetLength(0); Turnohehi++)
{
for (int Misparim = 0; Misparim < numbers.GetLength(1); Misparim++)
{
again:
Zmani = rnd.Next(1, 46);
for (int CheckRow = 0; CheckRow < numbers.GetLength(1); CheckRow++)
{
if (numbers[Turnohehi, CheckRow] == Zmani)
{
goto again;
}
}
numbers[Turnohehi, Misparim] = Zmani;
}
}
for (int Turnohehi = turNum; Turnohehi < numbers.GetLength(0); Turnohehi++)
{
if (Turnohehi == turNum)
{
for (int i = 0; i < 1; i++)
{
Console.WriteLine(“”);
Console.WriteLine(“******************************”);
Console.WriteLine(“Below are the winning numbers!”);
Console.WriteLine(“******************************”);
Console.WriteLine(“”);
}
}
for (int Misparim = 0; Misparim < numbers.GetLength(1); Misparim++)
{
Console.Write(“{0},”, numbers[Turnohehi, Misparim]);
}
Console.WriteLine();
}
for (int i = 0; i < numbers.GetLength(0); i++)
{
for (int t = 0; t < numbers.GetLength(1); t++)
{
for (int p = 0; p < numbers.GetLength(1); p++)
{
if (numbers[numbers.GetLength(0) - 1, t] == numbers[i, p])
{
pgia += 1;
}
}
}
if (i < numbers.GetLength(0) – 1)
{
Console.WriteLine(“In Row {0} you have {1} hits”, i + 1, pgia);
pgia = 0;
}
}
}
}
else if (option == 1)
{
Console.WriteLine(“Please choose number of Rows to fill in”);
int turNum = int.Parse(Console.ReadLine());
Console.WriteLine(“Are you sure?(y/n)”);
string Chose = Console.ReadLine();
if (Chose == “y” || Chose == “yes”)
{
int[,] numbers = new int[turNum+1, 6];
Random rnd = new Random();
int Zmani = new int();
for (int CurrentTur = 0; CurrentTur < numbers.GetLength(0); CurrentTur++)
{
for (int Misparim = 0; Misparim < numbers.GetLength(1); Misparim++)
{
again:
Zmani = rnd.Next(1, 46);
for (int CheckRow = 0; CheckRow < numbers.GetLength(1); CheckRow++)
{
if (numbers[CurrentTur, CheckRow] == Zmani)
{
goto again;
}
}
numbers[CurrentTur, Misparim] = Zmani;
}
}
for (int CurrentTur = 0; CurrentTur < numbers.GetLength(0); CurrentTur++)
{
if (CurrentTur == turNum)
{
for (int i = 0; i < 1; i++)
{
Console.WriteLine(“”);
Console.WriteLine(“******************************”);
Console.WriteLine(“Below are the winning numbers!”);
Console.WriteLine(“******************************”);
Console.WriteLine(“”);
}
}
for (int Misparim = 0; Misparim < numbers.GetLength(1); Misparim++)
{
Console.Write(“{0},”, numbers[CurrentTur, Misparim]);
}
Console.WriteLine();
}
for (int i = 0; i < numbers.GetLength(0); i++)
{
for (int t = 0; t < numbers.GetLength(1); t++)
{
for (int p = 0; p < numbers.GetLength(1); p++)
{
if (numbers[numbers.GetLength(0)-1, t] == numbers[i, p])
{
pgia += 1;
}
}
}
if (i < numbers.GetLength(0)-1)
{
Console.WriteLine(“In Row {0} you have {1} hits”, i+1, pgia);
pgia = 0;
}
}
}
}
else
{
Console.WriteLine(“Please Choose option 1 , 2 or 3 only!”);
goto Start;
}
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>