Skip to main content

C#: Program #24 (DoWhile Loop)

using System;

namespace DoWhile
{
    class Program
    {
        static void Main(string[] args)
        {
            Random no = new Random();
            int numbergenerated = no.Next(1,20);
            int numberguessed;
            int turns=0;

            do
            {
                if (turns != 0)
                {
                    Console.WriteLine("Guessed Wrong Number!");
                }
                Console.WriteLine("Guess a number between 1 and 20");
                numberguessed = Convert.ToInt32(Console.ReadLine());
                turns++;

            } while (numberguessed != numbergenerated);

            Console.WriteLine("Correct you got it in {0} turns",turns);
            Console.ReadKey();

        }
    }
}

Comments

Popular posts from this blog

C#: Program #15 (For Loop)

using System; namespace Loops {     class Program     {         static void Main(string[] args)         {                         object[] information = {"Gray", "14-Arid-4052", "Rawalpindi",21,3.80};             for (int i = 0; i < information.Length; i++)             {                 Console.WriteLine("The value of index {0} is {1}",i,information[i]);             }                 Console.ReadKey();         }     } }