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

2»

Comments

  • these is mine

    using System;


    namespace My_awesome_program

    {

        class Program

        {

            static void Main(string[] args)

            {

                Random numberGen = new Random();


                int r1 , r2;

                r1 = 0;

                r2 = 1;

                int atpts = 0;

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


                while (r1 != r2) {


                    Console.ReadKey();

                    r1 = numberGen.Next(1, 7);

                    r2 = numberGen.Next(1, 7);

                    Console.WriteLine("Dice 1: "+ r1);

                    Console.WriteLine("Dice 2: "+ r2 +"\n");

                    atpts++;

                }


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


                Console.ReadKey();

            }

        }

    }

  • using System;


    namespace MyAwesomeMathQuiz

    {

        class Program

        {

            static void Main(string[] args)

            {

                Random numberGen = new Random();


                int roll1 = 0;

                int roll2 = 1;

                int attempts = 0;


                Console.WriteLine("Press any key to roll both dices.");


                while(roll1 != roll2) {

                    Console.ReadKey();


                    roll1 = numberGen.Next(1, 7);

                    roll2 = numberGen.Next(1, 7);

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

                    attempts++;

                }


                Console.WriteLine("It took u " + attempts + (" attempts to roll same numbers!"));


               Console.ReadKey();

            }

        }

    }

  • I tried as well :D

    using System;


    namespace Best_Program

    {

        class Program

        {

            static void Main(string[] args)

            {  

                Random numberGen = new Random();

                int roll01 = 0;

                int roll02 = 0;

                int attemts = 0;

               

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


                while (roll01 != 6 || roll02 != 6)

                {

                    Console.ReadKey();

                    roll01 = numberGen.Next(1,7);

                    Console.WriteLine("Your first die rolled " + roll01);

                    roll02 = numberGen.Next(1,7);

                    Console.WriteLine("Your second die rolled " + roll02);

                    attemts++;

                }

                Console.WriteLine("It took you " + attemts + " attemts!");   

                Console.ReadKey();

            }

        }

    }

     

  • I tried too ended up good.

    using System;


    namespace Program

    {

        class Program

        {

            static void Main(string[] args)

            {

               //Program Title:

               Console.Title = "Two of a Kind";


               //Program Width:

               Console.WindowWidth = 150;


               //Font Color:

               Console.ForegroundColor = ConsoleColor.Yellow;


               //Content:

               Random numberGen = new Random();

               int dice1 = 0;

               int dice2 = 1;

               int attempts = 0;


               //Gameplay:

               Console.WriteLine("Welcome to Two of a Kind. This is a game of chance where you will have to roll two dice.");

               Console.WriteLine("If you get two if the same dice within 4 attempts, you win and will be rewarded with 100 lives.");

               Console.ForegroundColor = ConsoleColor.Red;

               Console.WriteLine("But if you don't, you will lose the number of lives equal to the attempts that you have made.");

               Console.WriteLine("GOODLUCK :)");

               Console.ReadKey();

               Console.ForegroundColor = ConsoleColor.Yellow;

               while (dice1 != dice2)

               {

                   dice1 = numberGen.Next(1, 7);

                   dice2 = numberGen.Next(1, 7);

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

                   Console.WriteLine("You rolled: "+ dice2 + "\n");

                   Console.ReadKey();

                   attempts++;

               }

               Console.WriteLine("Press ENTER to know the number of you attempts...");

               Console.ReadKey();

               Console.WriteLine("You have made " + attempts + " attempts...");

               Console.ReadKey();

               if (attempts <= 4)

               {

                   Console.WriteLine("You have passed. Receive the blessing of IMMORTALITY!");

               } else 

               {

                   Console.ForegroundColor = ConsoleColor.Red;

                   Console.WriteLine("You have failed mortal. RECEIVE THE PUNISHMENT FOR THE WICKED!!!");

               }

               //Ending Sequence:

               Console.WriteLine("Press ENTER to know the next judgement.....");

               Console.ReadKey();

            }

        }

    }

  • love this series of tutoriasl and it's really helping me to acomplish my goal of learning to code at least a bit!!

    so i made my version and had no problem doing my two dices program and the i tried to make it like a trow dice against the computer but for some reason i still can't make it work. help!!!


    Console.WriteLine("Ok " + name + " Let's play Dice!!");

          Console.WriteLine("First you roll and then I roll, Wins the bigger number every turn");


          Random numberGen = new Random();

          int roll1 = 0;

          int roll2 = 1;

         

          Console.WriteLine("READY....Press ENTER to roll");

                

          if ( roll1 == roll2){

            Console.ReadKey();

            Console.WriteLine("Nice tie, let's do it again!!");

                   }


          while (roll1 < roll2)

          {

            Console.ReadKey();

            roll1 = numberGen.Next(1, 7);

            roll2 = numberGen.Next(1, 7);

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

             

            Console.WriteLine(" I win, Let's go again");

            Console.WriteLine(" PRESS ENTER");

            //Console.ReadKey();

          }

                 

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

             

            Console.WriteLine ("YOU WIN!!!");

            //Console.ReadKey();

            


          Console.ReadKey(); 

  • I don't understand why you set roll2 to 1

  • Victor me too idk why

    @Victor16

  • somebody explained it to me

    It's because when you tried to enter into the while loop they would both be 0 therefore (role1 != role2) would be false and the loop would never start.


    @GostGK_YT

Sign In or Register to comment.