C# – 3 – Dice Program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiceProgram
{
class DiceProgram
{
static void Main(string[] args)
{
int guess;
string middleMan;
Console.WriteLine(“Welcome to the Kurosh’s dice program”);
Random random = new Random();

for (int i = 0; i < 200; i++)
{
int die = (int)((random.NextDouble() * 6) + 1);
Console.WriteLine("Computer has generated a random number from 0 – 6");
Console.Write("Try to guess the number on the dice: ");
middleMan = Console.ReadLine();
guess = int.Parse(middleMan);
if (guess == die)
{
Console.WriteLine("You have guessed correctly! The number of the dice was {0}", guess);
}
else if (guess != die)
{
Console.WriteLine("Your guess was wrong! You typed {0} but the computer generated number was {1}", guess, die);
}
Console.WriteLine();
}
}
}
}

C# – 2 – Simple keyboard reader

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class KeyBoardInputAndOutput
{
public static void Main()
{
Console.TreatControlCAsInput = true;
ConsoleKeyInfo key;

Console.WriteLine(“Press the buttons on the keyboard to see the output”);

do
{
key = Console.ReadKey();
Console.WriteLine(” : is your input.”);
if ((key.Modifiers & ConsoleModifiers.Alt) != 0)
{
Console.Write(“ALT+”);
}
else if ((key.Modifiers & ConsoleModifiers.Shift) != 0)
{
Console.Write(“SHIFT+”);
}
else if ((key.Modifiers & ConsoleModifiers.Control) != 0)
{
Console.Write(“CTL+”);
}

Console.WriteLine(key.Key.ToString() + ” : is system print.”);

} while (key.Key != ConsoleKey.Escape);
}
}

C# – 1 – Simple input

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleApplication
{
class Program
{
static void Main(string[] args)
{
string username;
string age;
string department;

Console.WriteLine(“What is your name: “);
username = Console.ReadLine();

Console.WriteLine(“What is your age: “);
age = Console.ReadLine();

Console.WriteLine(“What is your occupation: “);
department = Console.ReadLine();

Console.WriteLine(“Your name is ” + username
+ ” \nand your age is ” + age + ” and you work in the ”
+ “\””+department+”\” department.”);
Console.ReadLine();
}
}
}