Make a game in C#, in which give 5 tries to the user to guess the value of the number.

 CODE:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace For_Loop_lab6

{

    class Program

    {

        static void Main(string[] args)

        {

            DateTime dt = DateTime.Now;

            Console.WriteLine("{0}", dt);

             int secnum = 10;

            int tries = 5;

            int usetries = 0;

            for (int i = 1; i <=tries; i++)

            {

                Console.WriteLine("Enter Guessed Number:");

                int gesnum = Convert.ToInt32(Console.ReadLine());

                usetries++;

                if (gesnum == secnum)

                {

                    Console.WriteLine("\"Congratulation you won this game\"");

                    break;

                }

                else

                {

                    Console.WriteLine("You Enter Wrong Number try again");

                }

                if(tries==usetries)

                    {

                    Console.WriteLine("Sorry You Have Used Your {0} Tries",tries);


                }

            }


        }

    }

}




Comments

Popular posts from this blog

Vertical and Reverse Paramid in c# using loop.

Calculator in c# using Static Methods

Calculator in c# using Method void method