Just like some of you out there I was interested in learning C# so I decided to pick up a book. I'm still learning on console apps and have not progressed beyond strings and simple math operators. But I wanted to share a program that I recently created since this code could help other new programmers to develop a random number generator for the lotto or something cool like that.
Anyways, here is an excercise I took from my book.
Well I hope this was useful to someone. Remember this was a console application for when you begin your new program in visual studio.Code:using System; namespace ch2_6 { /// <summary> /// Choose the number of sides of the die, /// roll once and generate a random number. /// </summary> class DieRoll { /// <summary> /// Program Created by Oscar Valles /// </summary> [STAThread] static void Main(string[] args) { double sides; int answer; //random object is in this System Namespace Random generator = new Random(); Console.WriteLine("How many sides do you want in the die?: "); Console.Write("Please enter a number: "); //Take user input and change to integer sides = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(); //Display number chosen Console.WriteLine("You chose {0} sides", sides); Console.WriteLine(); Console.WriteLine("Below is a random roll"); //Have variable "answer" output a random roll answer = (int)(generator.NextDouble()*sides)+1; //Display Answer Console.WriteLine(); Console.WriteLine("Your Random Roll is: {0}", answer); Console.WriteLine(); Console.ReadLine(); }//end Main }//end Class "DieRoll" }//end namespace
I have some tutorials and books I can share if any newbies need any guides or references.



LinkBack URL
About LinkBacks


