Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

BRACKEYS - Solution to C# Tutorial 04 Challenge

BrackeysBrackeys Administrator
edited June 2020 in Announcements

Hey everyone!

Here is my solution to the challenge from the C# Tutorial 04 (Loops) video that is out soon.

Have fun with it! 😀

using System;

namespace My_Awesome_Program
{
  class Program
  {
    static void Main(string[] args)
    {
      Random numberGen = new Random();

      int roll01 = 0;
      int roll02 = 1;
      int attempts = 0;

      Console.WriteLine("Press enter to roll the dice.");
       
      while(roll01 != roll02)
      {
        Console.ReadKey();
         
        roll01 = numberGen.Next(1, 7);
        roll02 = numberGen.Next(1, 7);
         
        Console.WriteLine("Roll 1: " + roll01);
        Console.WriteLine("Roll 2: " + roll02 + "\n");

        attempts++;
      }

      Console.WriteLine("It took you " + attempts + " attempts to roll two of a kind.");

      // Wait before closing
      Console.ReadKey();
    }
  }
}
«13

Comments

  • EkosuEkosu Member

    lol first




    using System;


    namespace The_Test_Object

    {

        class Program

        {

            static void Main(string[] args)

            {


                //Dope Title


                Console.ForegroundColor = ConsoleColor.White;

                Console.BackgroundColor = ConsoleColor.Black;

                Console.Title = "fps game 2000";


                //Program


                Random rnum = new Random();


                int rolls01 = 0;

                int rolls02 = 0;

                int attemps = 1;

                int result = 0;


                Console.WriteLine("Press any key to roll the dice.");


                while(rolls01 != rolls02){


                    Console.ReadKey();


                    rolls01 = rnum.Next(1, 7);

                    rolls02 = rnum.Next(1, 7);

                    Console.WriteLine("You Rolled: " + rolls01 + " :"  + rolls02);


                }


                Console.WriteLine("It took you " + attemps + " to roll the same number twice.");


                //Close thingy


                Console.ForegroundColor = ConsoleColor.Red;

                Console.WriteLine("--Press any key to exit--");

                Console.ReadKey();

            }

        }

    }

  • AtsuAtsu Member

    Ok this was my first attempt at it:


    using System;
    
    
    
    
    namespace Project
    
    {
    
        class Program
    
        {
    
            static void Main(string[] args)
    
            {
    
                //@Atsu: This is how you comment.
    
    
    
    
                Console.Title = "Learning and Stuff";
    
    
    
    
                Random numGen = new Random();
    
    
    
    
                int r01 = numGen.Next(1, 7);
    
                int r02 = numGen.Next(1, 7);
    
                int attempt = 0;
    
    
    
    
                Console.WriteLine("Press any button to roll the dice.");
    
    
    
    
                while(r01 != r02) {
    
                    Console.ReadKey();
    
                    r01 = numGen.Next(1, 7);
    
                    r02 = numGen.Next(1, 7);
    
                    Console.WriteLine("\nDice 1: " + r01 + "\nDice 2: " + r02);
    
                    attempt++;
    
                }
    
    
    
    
                Console.WriteLine("It took you " + attempt + " attempts to get a matching pair of dice.");
    
                Console.ReadKey(); //@Atsu: Requires user input to close the program
    
            }
    
        }
    
    }
    
    
    
    

    I didn't think I could set the variables to something like say 0 and 1 because I thought that it was too simple of a solution to it but it's great to see that it is a correct method of doing doing it. With the way I set it up on this, it prevented me from being able to set a goto scenario that would start the program over again as every time I went to debug, the numbers for the variables would always match and I'd never get the chance to roll the dice.


    Anyways, thanks for the new video and this tutorial series, I'm having a fun time trying to finally learn how to code!

  • Just modified it a bit:





    using System;


    namespace cstesting

    {

        class Program

        {

            static void Main(string[] args)

            {

                Random numberGen = new Random();


                int roll1 = 0;

                int roll2 = 1;

                int attempts = 0;


                Console.WriteLine("How many attempts do you want to have: ");

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


                Console.WriteLine("Type an number that is the min of the random numbers: ");

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


                Console.WriteLine("Type an number that is the max of the random numbers: ");

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



                Console.WriteLine("Your settings:  MaxAttempts: " + maxattempts + " MinNumber: " + minNumber + " MaxNumber: " + maxNumber);

                Console.WriteLine("Press Enter to roll the dice!");



                while (roll1 != roll2 && attempts < maxattempts)

                {   

                      

                    Console.ReadKey();


                    roll1 = numberGen.Next(minNumber, maxNumber);

                    roll2 = numberGen.Next(minNumber, maxNumber);

                    Console.WriteLine("Roll 1: " + roll1);

                    Console.WriteLine("Roll 2: " + roll2);

                    attempts++;

                    

                }


                if (roll1 == roll2)

                {

                    Console.WriteLine("It took you " + attempts + " attempts to get two same numbers");

                }


                if (attempts >= maxattempts) 

                {

                    Console.WriteLine("You reached the max amount of attempts!");

                }





                Console.ReadKey();

            }

        }

    }

  • My One

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    
    namespace TeleTraan1
    {
        class Cool_Program
        {
            static void Main(string [] args)
            {
    
    
                Random numGen = new Random();
                int roll1 = 0;
                int roll2 = 0;
                int attempts = 0;
                while (roll1 != roll2)
                {
                    attempts++;
                    roll1 = numGen.Next(1, 7);
                    roll2 = numGen.Next(1, 7);
    
    
                    Console.WriteLine("Roll no.1 = " + roll1);
                    
                    Console.WriteLine("Roll no.2 = " + roll2);
                    
                    if (roll1 == roll2)
                    {
                        Console.WriteLine("It took you " + attempts + "attempts to roll 2 dice at once");
                        break;
                    
                    }
                    
                    else
                    
                    {
                    
                        Console.ReadKey();
                        
                    }
    
    
                }
                Console.ReadKey();
    
    
            }
        }
    }
    
    
    
  • Foot_forkCodeFoot_forkCode Member
    edited July 2020

    My Dad told me that the singular of dice is die so whenever I say die, I'm referring to dice.


    using System;


    namespace Dice_loop_brackeys_assignment

    {

        class Program

        {

            static void Main(string[] args)

            {

                // Title

                Console.Title = "Roll the dice";


                // Variables

                Random numGen = new Random ();

                int die1 = 1;

                int die2 = 0;

                int attempts = 0;


                // Introduction

                Console.WriteLine ("Hello and welcome to roll the dice.");


                // Code

                Console.WriteLine ("Press enter to play.");


                while (die1 != die2)

                {

                    Console.ReadKey ();


                    die1 = numGen.Next (1, 7);

                    die2 = numGen.Next (1, 7);

                    Console.WriteLine ("Die 1 number = " + die1 + ". Die 2 number = " + die2 + ".");

                    attempts++;

                }

                

                Console.WriteLine ("It took you " + attempts + " attempt to roll the same number on both die.");


                // Wait for keyboard input before closing

                Console.ReadKey ();

            }

        }

    }

  • When I am assigning both roll1 and roll2 variables with 0 the program doesn't work but if I assign any of roll1 and roll2 with 1 the program works fine. Can anyone tell me why this happens?

    using System;
    
    
    namespace Awesome_Projects
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.Title = "FRIDAY";
    
    
                Random numberGen = new Random();
    
    
                //Setting Variables
                int roll1 = 0;
                int roll2 = 1;
                int attempt = 0;
    
    
                Console.WriteLine("Press any key to roll the dice!");
    
    
                while(roll1 != roll2)
                {
                    Console.ReadKey();//User Input
    
    
                    //Generating dice numbers
                    roll1 = numberGen.Next(1, 7);
                    roll2 = numberGen.Next(1, 7);
                    
                    //Output
                    Console.WriteLine("You rolled a: " + roll1);
                    Console.WriteLine("You rolled a: " + roll2);
                    Console.WriteLine("\n");
    
    
                    attempt++;
                }
                Console.WriteLine("It took "+ attempt + " attempts to roll same number on both die.");
                Console.ReadKey();
            }
        }
    }
    
    
    
  • DaskielDaskiel Member
    edited July 2020

    My script works, but is there something that I should improve?

    using System;
    
    
    
    
    namespace Test
    
    {
    
        class Program
    
        {
    
            static void Main(string[] args)
    
            {
    
                Random numberGen = new Random();
    
    
    
    
                int rollX = 0;
    
                int rollY = 0;
    
                int attempts = 0;
    
    
    
    
                Console.WriteLine("Press enter to roll the dice.");
    
    
    
    
                while(rollX != 6 || rollY != 6) {
    
                    Console.ReadKey();
    
    
    
    
                    rollX = numberGen.Next(1, 7);
    
                    rollY = numberGen.Next(1, 7);
    
                    Console.WriteLine("Roll 1: " + rollX);
    
                    Console.WriteLine("Roll 2: " + rollY);
    
                    attempts++;
    
                }
    
                
    
                Console.WriteLine("It took you " + attempts + " attempts to roll two of a kind.");
    
                
    
                
    
                Console.ReadKey();  
    
            }
    
            
    
        }
    
    }
    
    
    
    
  • Tried to make a triple dice game but didn't work tho


    using System;


    namespace Coding

    {

        class Program

        {

            static void Main(string[] args)

             {


            Random NumberGen = new Random ();


            int roll1 = 0;

            int roll2 = 1;

            int roll3 = 2;

            int attempts = 0;


            Console.WriteLine("Press enter to roll the dice");


           

            while (roll1 != roll2 != roll3)

            {

                Console.ReadKey();


                roll1 = NumberGen.Next(1, 7);

                roll2 = NumberGen.Next(1, 7);

                roll3 = NumberGen.Next(1, 7);


                Console.WriteLine("Roll 1: " + roll1);

                Console.WriteLine("Roll 2: " + roll2 + "\n");

                Console.WriteLine("Roll 3: " + roll3 + "\n");


                attempts++;

            }

               

            Console.WriteLine("It took you " + attempts + " attempts to roll a triple, get better");


                Console.ReadKey();

            }

        }

    }

  • DexyelDexyel Member

    No surprises there, got the exact same code!

    using System;
    
    namespace _1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.Title = "Brackeys Tutorials 4";
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WindowHeight = 40;
    
                Random rollsGen = new Random();
    
                int roll1 = 0;
                int roll2 = 1;
                int attempts = 0;
    
                Console.WriteLine("Press ENTER to roll the dices until you get TWO OF A KIND!");
    
                while(roll1 != roll2)
                {
                    Console.ReadKey();
                    
                    roll1 = rollsGen.Next(1, 7);
                    roll2 = rollsGen.Next(1, 7);
    
                    Console.WriteLine("Roll 1: " + roll1);
                    Console.WriteLine("Roll 2: " + roll2 + "\n");
    
                    attempts++;
                }
    
                Console.WriteLine("It took you " + attempts + " to get TWO OF A KIND!");
            }  
        }
    }
    
  • EchraProgEchraProg Member
    edited July 2020

    Kinda realized you couldnt have both of the rolls default to 0 lol

    Also you can use emojis in the console title but idk how to get it to work in the actual code :(

    using System;


    namespace Awesome_Program

    {

        class Program

        {

            static void Main(string[] args)

            {


                Console.Title = "Dice Roller🎲🎲";

                Console.ForegroundColor = ConsoleColor.DarkCyan;


                Random numberGen = new Random();


                

                int roll1 = 0;

                int roll2 = 1;

                int attempts = 0;


                Console.WriteLine("Press enter to roll the dice");


                while (roll1 != roll2) {

                    Console.ReadKey();


                    roll1 = numberGen.Next(1, 7);

                    roll2 = numberGen.Next(1, 7);


                    Console.WriteLine("Roll 1: " + roll1);

                    Console.WriteLine("Roll 2: " + roll2);



                    attempts++;

                }


                Console.WriteLine("It took you " + attempts + " attempts to roll two of a kind.");


                Console.ForegroundColor = ConsoleColor.DarkGreen;

                Console.WriteLine("Do you want to roll again? If so press any key to continue");


                //Wait before closing

                Console.ReadKey();

            }

        }

    }

  • EylamEylam Member

    using System;


    namespace roll_a_dice

    {

      class Program

      {

        static void Main(string[] args)

        {

          Random numberGen = new Random();


          int roll1 = 0;

          int roll2 = 1;

          int attempts = 0;



          Console.WriteLine("Press enter to roll a dice.");


          while (roll1 != roll2)

          {

            Console.ReadKey();


            roll1 = numberGen.Next(1, 11);

            roll2 = numberGen.Next(1, 11);

            Console.WriteLine("Roll 1: " + roll1);

            Console.WriteLine("Roll 2: " + roll2);

            attempts++;

          }


          Console.WriteLine("It took you " + attempts + " attempts to roll two of a kind");



          //Wait before closing

          Console.ReadKey();

        }

      }

    }

  • using System;

    using System.Threading;


    namespace Idk_Whats_this

    {

       class Program

       {

           static void Main(string[] args)

           {


               //The variables

               int dice1, dice2;

               int attempts = 0;

               //Those Are the randoms

               Random roll1 = new Random();

               Random roll2 = new Random();

               //Some Chat that i thought would be funny

               Console.WriteLine("Welcome to the Dice Rollers L.T.D Company, Press any key to start");

               Console.ReadKey();

               Console.WriteLine("What We do here is simply rolling 2 dices and if they look alike in 3 attempts, YOU'LL WIN THE JACKPOT");

               Console.ReadKey();

               Console.WriteLine("SO WITHOUT ANY FURTHER ADO LETS START");

               Console.ReadKey();


               dice1 = roll1.Next(1, 7);

               Start:

               dice2 = roll2.Next(1, 7);

               while (dice1 != dice2 && attempts < 3)

               {

                   dice1 = roll1.Next(1, 7);

                   dice2 = roll2.Next(1, 7);

                   Console.WriteLine("\n\nDice one rolled : " + dice1);

                   Console.WriteLine("Dice two rolled : " + dice2);

                   attempts++;

                   Console.ReadKey();

               }

               if (attempts < 3 && dice1 == dice2)

               Console.WriteLine("Congrats, YOU WON THE JACKPOT");

               Console.ReadKey();

               Console.Write("Do you want to play again? (y/n) : ");

               string answer = Console.ReadLine();

               if (answer == "y")

               {

                   attempts = 0;

                   goto Start;


               }

               else if (answer == "n")

               {


                   Console.WriteLine("Thx For Playing C U L8R");


               }

               Console.ReadKey();


               attempts = 0;


               if (attempts == 3)

               {

                   Console.WriteLine("Sorry you lost, But do you want to play again? (y/n)");

                   attempts = 0;

                   string answer1 = Console.ReadLine();

                   if (answer1 == "y")

                   {

                       goto Start;


                   }

                   Console.ReadKey();

                   if (answer == "n")

                   {


                       Console.WriteLine("Thx For Playing C U L8R");


                   }

                   Console.ReadKey();


               }


           }

       }

    }

    Here it is, but I added my touch for it

  • I also Did it!!!! Cheers!

    using System;


    namespace WhileLoopProgram

    {

       class Program

       {

           static void Main(string[] args)

           {

               Random numGen = new Random();


               int roll = 5;

               int roll2 = 6;

               int attempts = 0;



               Console.WriteLine("Press enter to roll the die");


               while(roll != roll2)

               {

                   Console.ReadKey();


                   roll = numGen.Next(1, 7);

                   roll2 = numGen.Next(1, 7);


                   Console.WriteLine("You rolled a " + roll + " on the first dice.");

                   Console.WriteLine("You rolled a " + roll2 + " on the second dice.");

                   Console.WriteLine();


                   attempts++;

               }


               Console.WriteLine("It took you " + attempts + " attemps to roll a two-of-a-kind.");


           }

       }

    }

  • How to make the program compare three dice rolls instead of two? :) I try but it doesn't work ...


    I know that in the example above I have a loop for two arguments written, but I don't know how to write it so that it works for three dice rolls.

  • here's my solution! i've done these before but never posted here yet :D hello!

    also quick question i've noticed people have identifying colors for certain things on their consoles, how do I see those constantly?

    (apologies if it's too small to read there are plenty of others and ignore my little notes i have fun doing those : ) )

  • ZaeZae Member

    I have been following along as well and am just starting as well, but i like to add a spin onto your challenges for me and though they take me more time i enjoy them more so here is my iteration on the challenge.

    If you see things that dont make sense or could have been done better please do tell me. :)

    ( any labels or things that seem out of place is because this is apart of a much larger console projects filled with a bunch of other mini projects like this just to keep as a guide for my self )

     whileloop: Console.WriteLine("Lets play a game    (Click Enter To Begin)");
                Console.ReadKey();
                Console.Clear();
                Console.WriteLine("Its simple you will roll two Four Sided Dice\nYou win if you can get a matching pair in under 10 tries   (Press Enter To Contuine)");
                Console.ReadKey();
                Console.Clear();
                retry: Console.WriteLine("Press enter the roll the dice, Good luck");
                
                int roll = 0;
                int roll2 = 1;
                int attempts= 0;
    
    
                Random numberGen = new Random();
    
    
               
    
    
                while(roll != roll2 && attempts <= 9)
                {
                    Console.ReadKey();
                    roll = numberGen.Next(1, 7);
                    roll2 = numberGen.Next(1, 7);
                    Console.WriteLine("Roll 1: " + roll);
                    Console.WriteLine("Roll 2: " + roll2 + "\n");
                    attempts++;
                }
                
                if (attempts < 9)
                {
                   Console.WriteLine("YOU WIN\nGood job you won in " + attempts + " attempts to roll a pair");
                   Console.ReadKey();
                   Console.Clear();
                   Console.WriteLine("Do you want to retry  (Yes or No");
                }
                else
                {
                   Console.WriteLine("You Failed\nDo you want to retry  (Yes or No");
                }
                wronga:
                string answer11 = Convert.ToString(Console.ReadLine());
                
                switch(answer11)
                {
                    case "Yes":
                        Console.Clear();
                        goto retry;
                    case "No":
                        Console.WriteLine("Good bye then.\n(You Will Now Be Redirected To The Menu)");
                        Console.ReadKey();
                        Console.Clear(  );
                        goto MenuS;
                    default:
                        Console.WriteLine("This is not an answer please say YES or NO");
                        goto wronga;
                }
    


  • Wings30306Wings30306 Member
    edited August 2020

    I have some friends who are avid DnD players with several types of dice, so I made it so the die could have any value they choose. (PS: my first time on this forum, how to I add clean code as @Zae did?)


    Console.Write("What is the maximum value of the dice you want to use? ");

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

                Random numberGen = new Random();


                int roll = 0;

                int die1 = 0;

                int die2 = 1;


                Console.WriteLine("Press Enter to roll the die.");


                while (die1 != die2) {

                    roll++;

                    Console.ReadKey();

                    die1 = numberGen.Next(1, dieValue + 1);

                    die2 = numberGen.Next(1, dieValue + 1);

                    if (die1 == die2) {

                        Console.WriteLine("Yay, you have rolled doubles of value " + die1 + "! It took " + roll + " attempts.");

                    }

                    else 

                    {

                        Console.WriteLine("Sorry, the dice don't match. (" + die1 + " is not " + die2 + ".) Roll again!"); 

                    }

                      

                }


  • I was able to complete using || is there anything wrong with that or is roll1 != roll2 , just a better way of putting it?




    using System;


    namespace Project_1

    {

        class Program

        {

            static void Main(string[] args)

            {

               Random numberGen = new Random();


               int roll1 = 0;

               int roll2 = 0;

               int attempts = 0;

               

               Console.WriteLine("Press enter to roll the dice.");


                

                while (roll1 != 6 || roll2 != 6) { 

                Console.ReadKey();


               roll1 = numberGen.Next(1, 7);

               roll2 = numberGen.Next(1, 7);

               

               Console.WriteLine("You rolled: " + roll1);

               Console.WriteLine("You rolled: " + roll2);

               attempts++;


               }

               Console.WriteLine("It took " + attempts + " attempts for both dice to be a 6");


              Console.ReadKey();

            }

        }

    }

  • Here's My attempt


    using System;


    namespace WORK

    {

        class Program

        {

            static void Main(string[] args)

            {

                Random numberGen = new Random();

                

                int roll1 = 0;

                int roll2 = 1;

                int attempts = 0;

                    

                Console.WriteLine("press enter to roll the die.");

                

                while (roll1 != roll2)

                {

                    Console.ReadKey();   

                    

                    roll1 = numberGen.Next(1, 7);

                    Console.WriteLine("You rolled" + roll1);

                    

                    roll2 = numberGen.Next(1, 7);

                    Console.WriteLine("You rolled" + roll2);

                    

                    attempts++;

                }

                

                Console.WriteLine("It took " + attempts + " to roll doubles.");

                

                

                

                

                Console.ReadLine();

            }

        }

    }

  • So...

    On first attempt i set roll1 to 0 and roll2 to 0 and i was wondering why it didn't work. But i sitted for a while, tested different solutions and tada! Works.


    using System;


    namespace projekt

    {

        class Program

        {

            static void Main(string[] args)

            {

                

                Console.ForegroundColor = ConsoleColor.Green;

                Console.Title = ("Staver lesson #0008");


                Random numberGen = new Random ();


                Random numberGen2 = new Random ();


                int roll = 0;

                int roll2 = 1; 


                int attempts = 0;


                Console.WriteLine("press enter to roll the die.");


                while(roll != roll2){

                    Console.ReadKey();


                    roll = numberGen.Next(1, 7);

                    roll2 = numberGen2.Next(1, 7);

                    

                    Console.WriteLine("roll #1 = " + roll);

                    Console.WriteLine("roll #2 = " + roll2);


                    attempts++;

                }


                Console.WriteLine("it took you " + attempts + " attempts to roll a same number.");


                


                Console.ReadKey();

            }

        }

    }

  • Made so you can login and please make another vid




    using System;


    namespace my_awsome_program

    {

        class Program

        {

            static void Main(string[] args)

            {

                 string username = "Michnl";

                 string password = "BigMich";


                 string usernameused;

                 string passwordused;


                 Console.Write("Please enter your username: ");


                 usernameused = Console.ReadLine();

                 if(usernameused == username) {

                     Console.Clear();

                     Console.Write("Please enter your password: ");


                     passwordused = Console.ReadLine();

                     if(passwordused == password) {

                         Console.ForegroundColor = ConsoleColor.Green;

                         Console.Write("Correct!");

                     } else {

                         Console.ForegroundColor = ConsoleColor.Red;

                         Console.Write("Incorrect password!");

                     }

                 }else

                 {

                     Console.ForegroundColor = ConsoleColor.Red;

                     Console.Write("Incorrect username!");

                 }



                // wait before closing

                Console.ReadKey();

            }

        }

    }

  • using System;


    namespace Learning_C_

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.Title = "SouthMythKing";


                Random numGen = new Random();


                int secondRoll = 1;

                int firstRoll = 0;

                int rolls = 0;


                Console.WriteLine("Press Enter To Roll And See How Many Times It Take U To Roll A 5");



                while(roll01 != roll02)

                {

                    secondRoll = numGen.Next(1, 5);

                    firstRoll = numGen.Next(1, 5);

                    Console.ReadKey();

                    Console.WriteLine("You Rolled " + firstRoll + " And A " + secondRoll);

                    rolls++;

                }


                Console.WriteLine("It Took You " + rolls + " To Roll The Same Number");


                Console.ReadKey();

                Console.Title = "SouthMythKing";


            }

        }

    }

  • bloxxycatybloxxycaty Member
    edited August 2020

    using System;


    namespace roll

    {

    class Program

        {

    publicstaticvoidMain(string[] args)

            {

       Random numGen = new Random();


    int roll1 = numGen.Next(1,7);


    int roll2 = roll1 + 1;



    int attempts = 0;


       Console.WriteLine("Press any keys except esc to roll the dices");


    while (roll1 != roll2)


       {

       Console.ReadKey();


       roll1 = numGen.Next(1,7);


       roll2 = numGen.Next(1,7);



       Console.WriteLine("Roll 1: "+roll1+" Roll 2: " + roll2);


       attempts++;


    if (roll1 != roll2)

       {

           Console.WriteLine("Press again");

       }


       }


       Console.WriteLine("It tooks " + attempts + " attempts");


       Console.ReadKey();

            }

        }

    }

  • febryfebry Member
    edited August 2020

    Here's mine with 3 dice rolls and it works well, hope you guys can figure out the code :)

    Thank you so much for the tutorial Brackeys :)

    using System;
    
    
    namespace Testing
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                Random numGen = new Random();
              
    
                int roll1 = 0;
                int roll2 = 1;
                int roll3 = 2;
                int attempts = 0;
    
                Console.WriteLine("Press enter to roll the dice.");
    
                while (roll1 != roll2 || roll1 != roll3 || roll2 != roll3)
                {
                    Console.ReadKey();
                    roll1 = numGen.Next(1, 7);
                    roll2 = numGen.Next(1, 7);
                    roll3 = numGen.Next(1, 7);
                    Console.WriteLine($"Roll 1: {roll1} \nRoll 2: {roll2} \nRoll 3: {roll3}\n");
                    attempts++;
                }
    
                Console.WriteLine($"It took you {attempts} roll to get three of a kind");
    
    
    
                Console.ReadKey();
            }
            
        }
    }
    


  • Can someone tell me why "int roll02 = 1" ?

  • 2nd try: :)

    using System;


    namespace Dice_Challenge

    {

        class Program

        {

            static void Main(string[] args)

            { 

                Random numberGen = new Random();

                int roll = 0;

                int roll2 = 1;

                int attempts = 0;

                Console.WriteLine("Please press ENTER to roll");


                while (roll != roll2)

                {

                    Console.ReadLine();

                    roll = numberGen.Next(1, 7);

                    roll2 = numberGen.Next(1, 7);

                    Console.WriteLine("You roll: " + roll );

                    Console.WriteLine("You roll: " + roll2 );

                    attempts++;


                }

                Console.WriteLine("it took you " + attempts + " attempts to roll a same number.");



                          Console.ReadKey();

            }

        }

    }

  • My solution:

    using System;


    namespace tutorial

    {

    class Program

    {

    static void Main(string[] args)

    {

    Console.Title = ".NET Core";

    Console.ForegroundColor = ConsoleColor.Green;

    Console.Write("\n");

    Console.ReadKey();


    Random numGen = new Random();


    int roll = 0;

    int roll2 = 0;

    int attempts = 0;


    Console.WriteLine("Press any key to role the die.");


    do

    {

    Console.ReadKey();

    roll = numGen.Next(1, 7);

    roll2 = numGen.Next(1, 7);

    attempts++;

    Console.WriteLine("Attempt " + attempts + ". Roll 1: " + roll + " Roll 2: " + roll2);

    } while (roll != roll2);


    Console.WriteLine("It took you " + attempts + " attempts");


    Console.ReadKey();

    return;

    }

    }

    }

  • this was my first also i saw somebody asking why roll02 = 1, its so when you first start the program you dont win right away

    using System;


    namespace My_Awesome_Program

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.WindowHeight = 40;

                Console.WindowWidth = 100;


                Random numberGen = new Random();


                int roll01 = 0;

                int roll02 = 1;

                int attempts = 0;


                Console.WriteLine("Press enter to roll the die");


                while(roll01 != roll02) {

                    Console.ReadKey();


                    roll01 = numberGen.Next(1, 7);

                    roll02 = numberGen.Next(1, 7);

                    Console.WriteLine("Roll 1: " + roll01);

                    Console.WriteLine("Roll 2: " + roll02);

                    Console.WriteLine();

                    attempts++;

                }


                Console.WriteLine("It took you " + attempts + " to roll doubles");


                // Wait before closing

                Console.ReadKey();

            }

        }

    }

  • This is how i did it :3




    using System;


    namespace Loop2

    {

        class Program

        {

            static void Main(string[] args)

            {

                Random numberGen = new Random();


                int roll1 = 0;

                int roll = 0;

                int attempts = 0;


                Console.WriteLine("Press enter to roll the dice.");



                while(roll1 != 8 && roll != 2)   {  

                    Console.ReadKey();

                    

                    roll1 = numberGen.Next(1, 9);

                    roll = numberGen.Next (1, 7);

                    Console.WriteLine("You rolled: " + roll1);

                    Console.WriteLine("You rolled: " + roll);

                    attempts++;

                }


                Console.WriteLine("It took you " + attempts + " attempts to roll a six.");

                //Wait before closing

                Console.ReadKey();

            }

        }

    }

  • it took me sooo long and all i had to do is fix last mistake witch was change 0 from int roll0 = 0; to 1

    lol love the series im going slow so i dont have to wait for next lesson but im already on arrays but at end ill re do everything of mememory

    using System;


    namespace for_loop_C_

    {

        class Program

        {

            static void Main(string[] args)

            {

                Random numberGen = new Random();


                int roll01 = 0;

                int roll02 = 1;

                int attempts = 0;


                Console.WriteLine("press enter to roll the dice. ");


                while (roll01 != roll02)

                {

                    Console.ReadKey();


                    roll01 = numberGen.Next(1, 7);

                    roll02 = numberGen.Next(1, 7);

                    

                    Console.WriteLine("roll 1: " + roll01);

                    Console.WriteLine("roll 2: " + roll02 + "\n");


                    attempts++; 

                }

                

                Console.WriteLine("it took you " + attempts + " attempts to roll a two of a kind.");


                // wait before closing

                Console.ReadKey();

            }

        }

    }

Sign In or Register to comment.