Giter VIP home page Giter VIP logo

number_guessing_game's People

Contributors

lyseriuos avatar

Watchers

 avatar

number_guessing_game's Issues

Consistency is key

if (randomNumber > userNumber && i >= 1) // if the random number is higher than user's input number
{
Console.WriteLine($"Too Low! Left attempts: {i}");
}
if (-5 <= numberRange && numberRange <= 5 && i >= 1) // if user's number is lower up to 5 or higher up to 5 random number
Console.WriteLine($"You are close!");

Try to be consistent within your codebase, regarding indentation and placing of curly brackets

show the user the random number

Just a suggestion, but if the user did not quess the correct number, it would be nice to show him, what the hidden number was :)

combine condition checks into one condition

// i >= 1 is to filter output after the last try, user will get only "Try again!" output instead of all possible
if (randomNumber < userNumber && i >= 1) // if the random number is lower than user's input number and {i} is bigger than 1
{
Console.WriteLine($"Too High! Left attempts: {i}");
}
if (randomNumber > userNumber && i >= 1) // if the random number is higher than user's input number
{
Console.WriteLine($"Too Low! Left attempts: {i}");
}
if (-5 <= numberRange && numberRange <= 5 && i >= 1) // if user's number is lower up to 5 or higher up to 5 random number
Console.WriteLine($"You are close!");

Instead of checking if "i >= 0" vor every if-condition, you could wrap it around your checks.

Also think about if you really need to calculate number range for every guess?

using Math.Abs

if (-5 <= numberRange && numberRange <= 5 && i >= 1) // if user's number is lower up to 5 or higher up to 5 random number

Instead of checking for the positive and negative range, you could use the Math.Abs function and only compare for the flat value
https://learn.microsoft.com/en-us/dotnet/api/system.math.abs?view=net-7.0

This way you could also even omit the declaration of the numberRange variable at all,
because Math.Abs can also work with mathematic expressions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.