DEV Community

Shubham Singh
Shubham Singh

Posted on

Build a Number Guess Application in C# .NET

Alt Text

Simple Game Build to start with C# in VS

Code

using System;

namespace NumberGusser
{
    //Main Class 
    class Program
    {
        //Entry Point Method
        static void Main(string[] args)
        {
            // set app variable
            string m_appName = "Number Guesser";
            string m_appVersion = "1.0.0";
            string m_appAuthor = "@imshubh17";

            //change text color for app info
            Console.ForegroundColor = ConsoleColor.Green;

            //write out app info
            Console.WriteLine("{0}: Version {1}, by {2}", m_appName, m_appVersion, m_appAuthor);

            //change text color to original
            Console.ResetColor();

            //ask user name
            Console.WriteLine("What is your name?");

            // get user name
            string userName = Console.ReadLine();

            Console.WriteLine("Hello {0}, Let's Play a GAME...", userName);
            //set Score
            int i_totalScore = 10;
            int i_initialScore = 11;

            //set correct Number
            int i_correctNumber = 7;

            //init guess var
            int i_guess = 0;

            //Ask User to guess number
            Console.WriteLine("Guess a number between 1 to 10");           

            //result 
            while (i_guess != i_correctNumber)
            {
                string userGuessInput = Console.ReadLine();
                i_guess = int.Parse(userGuessInput);
                i_initialScore--;
            }

            //print result
            Console.WriteLine("{0} Your Score: {1}/{2}", userName, i_initialScore, i_totalScore);
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)