How To Make Basic Lottery Program And Learn Arrays On Sharpdevelop #5
What Will I Learn?
Hello,in this tutorial ;
- You will learn coding c#
- You will learn how to code with Sharpdevelop
- You will learn how to make a basic lottery system
- You will learn defining new class and series.
- You will learn how to use arrays in c#
Requirements
- Sharpdevelop
- Basic knowledge of c# coding.
Difficulty
- Basic
Tutorial Contents
Hello,in this tutorial i am going to show you guys how to make a random lottery program with sharpdevelop using c# language as usual.In this tutorial you will also learn the usage of arrays and "random" variable.Let's get it started.
As usual we define our libraries to make our code work then naming our program and starting to code...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Basic_Lottery
class Program
static void Main(string[] args)
Here you learn a new thing if you are following my sharpcode program,we create new series in here and define them as you can see below.We make it [6] that means that series must have 6 members.That is a new array!
int[] Lottery = new int[6];
int[] Guessing = new int[6];
In this part we use random variable.When we use "random" the computer will draw random 6 numbers for us.Also defining lottery.lenght for below.
Random r = new Random();
for (int i = 0; i < Lottery.Length; i++)
Now we make our lottery numbers must between 1 to 50.
Lottery[i] = r.Next(1, 50);
Now in this part we will user Array.sort code type to sort numbers from small to large.
Array.Sort(Lottery);
In this part we use class called "guessing" we ask user to enter six numbers and guess them right to win lottery.As you know from previous tutorials of mine int.parse is used for to convert integer to type 32byte integer.
for (int i = 0; i < Guessing.Length; i++)
Console.Write((i + 1) + ". Enter Your Numbers: ");
Guessing[i] = int.Parse(Console.ReadLine());
Now we show results to user and find out the correct numbers that user entered.
Console.WriteLine("Drawing Result");
for (int i = 0; i < Lottery.Length; i++)
Console.WriteLine(Lottery[i]);
for (int j = 0; j < Guessing.Length; j++)
if (Lottery[i] == Guessing[j])
RightGuess++;
In the final step we show the final result and tell user how many correct numbers that user guessed right.
Console.WriteLine("Numbers you have selected right: " + RightGuess);
Console.ReadLine();
Output of the program ;
Curriculum
If you want to start from somewhere in c# coding keep up with me.More to come...
From first to last
https://steemit.com/utopian-io/@milliar/how-to-convert-mm-to-any-length-in-sharpdevelop
https://steemit.com/utopian-io/@milliar/how-to-use-datetime-method-on-sharpdevelop-4
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
The contribution should not have been approved because the project has not been actually updated within the last year. There is only a commit fixing the headings in the readme file but no update with the code.
You can contact us on Discord.
[utopian-moderator]
Unvoted for breaking the Utopian Rules https://utopian.io/rules