5. Guessing Game! | Intro To C# Programming

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ก.ย. 2024
  • Want to learn programming? This is an accelerated series to teach you the basics of programming in C#. We’ll make a few small games to help you learn important concepts! At the end of this series you’ll be ready for my next programming series where we’ll make a 2D game engine you can use to ship your own titles on PC, Mac, Linux, Xbox One, PlayStation 4, iOS, Android and more.
    If you found this tutorial useful, please consider picking up a copy of my game The Path of Motus: pathofmotus.com
    Follow me on Twitter: / michaelartsgame

ความคิดเห็น • 21

  • @simplyballing1592
    @simplyballing1592 5 ปีที่แล้ว +3

    Wonderful tutorial. Thanks a million

    • @michaelartsmedia
      @michaelartsmedia  5 ปีที่แล้ว

      Thanks for watching!

    • @andresviveros3994
      @andresviveros3994 5 ปีที่แล้ว

      @@michaelartsmedia Hello, do you have to use a while loop? I am training c sharp and been set the same challenge but using an if statement instead of a while loop. Thanks

    • @michaelartsmedia
      @michaelartsmedia  5 ปีที่แล้ว

      @@andresviveros3994 If you're making a console application you need some type of loop to keep the program going. If you just want to execute some code one time and have the program exit you can remove the while loop.

  • @donutdoesminecraft
    @donutdoesminecraft 3 ปีที่แล้ว +1

    Hi I am trying to make a guessing game which is player vs player instead of player vs computer? Could you help me with this. I am brand new to c# so some guidance would be helpful. Thank you

  • @greenguy5294
    @greenguy5294 6 ปีที่แล้ว +11

    That moment when you press F5 to run the program but you're accidentally on the video so it refreshes.

    • @michaelartsmedia
      @michaelartsmedia  6 ปีที่แล้ว +1

      haha dang, I never thought of that. I'm a big hotkey user but I forgot that also has a function on the browser xD

    • @elsawhere8107
      @elsawhere8107 6 ปีที่แล้ว

      I do that too sometimes, lol

  • @TwilightZone13
    @TwilightZone13 5 ปีที่แล้ว +2

    I am doing this for class and I am required to use a do while loop. How am supposed to us a do while loop for the random number guess program?

    • @michaelartsmedia
      @michaelartsmedia  5 ปีที่แล้ว

      Do while works like a for loop, it's just structured differently. Example:
      For (int i = 0; i < count; i++)
      Do code
      Turns into:
      Int i = 0;
      Int count = 5:
      Do
      {
      I++;
      }
      While (i < count)
      Just find a place that has a for loop and replace it like that. Good luck!

    • @TwilightZone13
      @TwilightZone13 5 ปีที่แล้ว

      @@michaelartsmedia This is my code. The class I am taking is in Swedish so that's why some things are not in English. The code is not finished yet.
      static void Main(string[] args)
      {
      Random randomer = new Random();
      int randomNumber = randomer.Next(1, 100);
      string guess;
      Console.WriteLine("Ett tal mellan 1-100 har slumpats.");
      Console.WriteLine("Se om du kan gissa vilket tal det är.");
      do
      {
      Console.Write("Tal: ");
      guess = Console.ReadLine();
      int guessNumber = Convert.ToInt32(guess);
      if (guessNumber == randomNumber)
      {
      Console.WriteLine("Grattis! Du har hittat rätt nummer.");
      Console.ReadLine();
      }
      else if (guessNumber < randomNumber)
      {
      Console.WriteLine("Dit svar är för lågt. Försök igen.");
      Console.ReadLine();
      }
      else if (guessNumber > randomNumber)
      {
      Console.WriteLine("Dit svar är för högt. Försök igen.");
      Console.ReadLine();
      }
      } while (guessNumber != randomNumber);
      For this line of code, while (guessNumber != randomNumber); guessNumber is underlined red. Why is that?

    • @michaelartsmedia
      @michaelartsmedia  4 ปีที่แล้ว +1

      @@TwilightZone13 You have defined guessNumber inside the do loop, so anything outside of the do brackets have no idea that it exists! If you look at your error list it probably says it doesn't exist in the current context. You just need to define that variable outside of the brackets.

  • @christianbulacan8943
    @christianbulacan8943 2 ปีที่แล้ว

    do u have a final product for this code?

  • @CamillasChannel
    @CamillasChannel 2 ปีที่แล้ว

    could I have your github name to follow your github account ?

  • @EngenMarcus
    @EngenMarcus 6 ปีที่แล้ว

    But if i get the number right, and restart without closing the program, the number of guesses does not restart. How do i do that?

    • @michaelartsmedia
      @michaelartsmedia  6 ปีที่แล้ว

      You should be able to simply set the variable that holds the number of guesses back to the starting value!

    • @EngenMarcus
      @EngenMarcus 6 ปีที่แล้ว

      Oh yeah of course thank you lol

    • @michaelartsmedia
      @michaelartsmedia  6 ปีที่แล้ว

      +Marcus Engen no problem!

  • @GazRam
    @GazRam 6 ปีที่แล้ว

    Is there a way where at the end I can make it so the computer says the number it was thinking of if the user gets it wrong?

    • @michaelhicks6714
      @michaelhicks6714 6 ปีที่แล้ว

      Hey! Using the write line function you can pass in the variable that has what the computer is thinking. just make sure when you do that you type .ToString() at the end to convert the number to a string.

    • @michaelhicks6714
      @michaelhicks6714 6 ปีที่แล้ว

      Hey! Using the write line function you can pass in the variable that has what the computer is thinking. just make sure when you do that you type .ToString() at the end to convert the number to a string.